std::numpunct_byname
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Text processing library
Regular expressions library (C++11)
Formatting library (C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++26)
Localization library
numpunct_byname
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
Defined in header
<locale>
template< class CharT >
class numpunct_byname : public std::numpunct <CharT>;
class numpunct_byname : public std::numpunct <CharT>;
std::numpunct_byname
is a std::numpunct facet which encapsulates numeric punctuation preferences of a locale specified at its construction.
Contents
[edit] Specializations
The standard library is guaranteed to provide the following specializations:
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 character I/O
[edit] Nested types
Type
Definition
char_type
CharT
string_type
std::basic_string <CharT>
[edit] Member functions
std::numpunct_byname::numpunct_byname
explicit numpunct_byname( const char* name, std::size_t refs = 0 );
explicit numpunct_byname( const std::string & name, std::size_t refs = 0 );
(since C++11)
Constructs a new std::numpunct_byname
facet for a locale with name.
refs is used for resource management: if refs == 0, the implementation destroys the facet, when the last std::locale object holding it is destroyed. Otherwise, the object is not destroyed.
Parameters
name
-
the name of the locale
refs
-
the number of references that link to the facet
std::numpunct_byname::~numpunct_byname
protected:
~numpunct_byname();
~numpunct_byname();
Destroys the facet.
Inherited from std::numpunct
Nested types
Type
Definition
char_type
CharT
string_type
std::basic_string <CharT>
[edit] Data members
Member
Description
Member functions
Protected member functions
[virtual]
(virtual protected member function of
std::numpunct<CharT>
) [edit]
[virtual]
(virtual protected member function of
std::numpunct<CharT>
) [edit]
[virtual]
(virtual protected member function of
std::numpunct<CharT>
) [edit]
[virtual]
(virtual protected member function of
std::numpunct<CharT>
) [edit]
[edit] Example
This example demonstrates how to apply numeric punctuation rules of another language without changing the rest of the locale.
Run this code
#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