std::numpunct_byname

From Cppreference

Jump to: navigation, search
Defined in header <locale>

template< class charT >
class numpunct_byname;

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

[edit] Member types

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

[edit] Member functions

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

[edit] 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

[edit] See also

numpunct
defines numeric punctuation rules
(class template)