From cppreference.com
template<classCharT>classnumpunct;The facet std::numpunct encapsulates numeric punctuation preferences. Stream I/O operations use std::numpunct through
and
for parsing numeric input and formatting numeric output.
The numbers that are supported by std::numpunct have the format described below. Here digit represents the radix set specified by the fmtflags argument value, thousands-sep and decimal-point are the results of
and
functions respectively.
The format of integer values is as follows:
integer ::= [sign] units sign ::= plusminus plusminus ::= '+' | '-' units ::= digits [thousands-sep units] digits ::= digit [digits] The number of digits between the thousand-seps (maximum size of digits) is specified by the result of
.
The format of floating-point values is as follows:
floatval ::= [sign] units [decimal-point [digits]] [e [sign] digits] | [sign] decimal-point digits [e [sign] digits] e ::= 'e' | 'E'
Inheritance diagram
Specializations
The standard library is guaranteed to provide the following specializations (they are
required to be implemented by any locale object
):
std::numpunct<char>provides equivalents of the "C" locale preferences std::numpunct<wchar_t>provides wide character equivalents of the "C" locale preferences Nested types
Type Definition char_typeCharTstring_typestd::basic_string<CharT>Data members
Member functions
constructs a new numpunct facet
(public member function)
destructs a numpunct facet
(protected member function)
invokes do_decimal_point
(public member function)
invokes do_thousands_sep
(public member function)
invokes do_grouping
(public member function)
invokes do_truename or do_falsename
(public member function)
Protected member functions
[virtual]
provides the character to use as decimal point
(virtual protected member function)
[virtual]
provides the character to use as thousands separator
(virtual protected member function)
[virtual]
provides the numbers of digits between each pair of thousands separators
(virtual protected member function)
[virtual]
provides the string to use as the name of the boolean true and false
(virtual protected member function)
Example
The following example changes the string representations of true and false:
Run this code
#include<iostream>#include<locale>structfrench_bool:std::numpunct<char>{string_typedo_truename()constoverride{return"vrai";}string_typedo_falsename()constoverride{return"faux";}};intmain(){std::cout<<"default locale: "<<std::boolalpha<<true<<", "<<false<<'\n';std::cout.imbue(std::locale(std::cout.getloc(),newfrench_bool));std::cout<<"locale with modified numpunct: "<<std::boolalpha<<true<<", "<<false<<'\n';}Output:
default locale: true, false locale with modified numpunct: vrai, faux Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++98 the sign token allowed an optional whitespace following + or -removed the whitespace See also
creates a numpunct facet for the named locale
(class template)