Namespaces
Variants
Views
Actions

std::numpunct_byname

From cppreference.com
< cpp‎ | locale
Revision as of 18:58, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
template< class charT >
class numpunct_byname : public std::numpunct<charT>;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

std::numpunct_byname is a std::numpunct facet which encapsulates numeric punctuation preferences of a locale specified at its construction.

Two specializations are provided by the standard library

Defined in header <locale>
std::numpunct_byname<char> locale-specific std::numpunct facet for narrow character I/O
std::numpunct_byname<wchar_t> locale-specific std::numpunct facet for wide characters I/O

Contents

Member types

Member type Definition
char_type charT
string_type std::basic_string<charT>

Member functions

constructs a new numpunct_byname facet
(public member function)
destructs a numpunct_byname facet
(protected member function)

Example

This example demonistrates how to apply numeric punctuation rules of another language without changing the rest of the locale.

#include <iostream>
#include <locale>
int main()
{
    const double number = 1000.25;
    std::wcout << L"default locale: " << number << L'\n';
    std::wcout.imbue(std::locale(std::wcout.getloc(),
                                 new std::numpunct_byname<wchar_t>("ru_RU.UTF8")));
    std::wcout << L"default locale with russian numpunct: " << number << L'\n';
}

Output:

default locale: 1000.25
default locale with russian numpunct: 1 000,25

See also

defines numeric punctuation rules
(class template)