< cpp‎ | locale
Revision as of 06:30, 23 April 2013 by P12 (Talk | contribs)


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

Defined in header <locale>

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

<td class="t-dcl-nopad">
template< class CharT >
class numpunct;

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

The facet std::numpunct encapsulates numeric punctuation preferences. Stream I/O operations use std::numpunct through std::num_get and std::num_put 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 Template:rlf and Template:rlf 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 Template:rlf.

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’
About this image

Inheritance diagram

Two specializations are provided by the standard library

Defined in header <locale>
std::numpunct<char> provides equivalents of the "C" locale preferences
std::numpunct<wchar_t> provides wide character equivalents of the "C" locale preferences


Member types

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

Member functions

Template:cpp/locale/numpunct/dcl list numpunctTemplate:cpp/locale/numpunct/dcl list ~numpunctTemplate:cpp/locale/numpunct/dcl list decimal pointTemplate:cpp/locale/numpunct/dcl list thousands sepTemplate:cpp/locale/numpunct/dcl list groupingTemplate:cpp/locale/numpunct/dcl list truefalsename

Protected member functions

Template:cpp/locale/numpunct/dcl list do decimal pointTemplate:cpp/locale/numpunct/dcl list do thousands sepTemplate:cpp/locale/numpunct/dcl list do groupingTemplate:cpp/locale/numpunct/dcl list do truefalsename

Member objects

static std::locale::id id
id of the locale
(public member object)


The following example changes the string representations of true and false

#include <iostream>
#include <locale>
struct french_bool : std::numpunct<char> {
    string_type do_truename() const { return "oui"; }
    string_type do_falsename() const { return "non"; }
int main()
    std::cout << "default locale: "
              << std::boolalpha << true << ", " << false << '\n';
    std::cout.imbue(std::locale(std::cout.getloc(), new french_bool));
    std::cout << "locale with modified numpunct: "
              << std::boolalpha << true << ", " << false << '\n';


default locale: true, false
locale with modified numpunct: oui, non

See also

creates a numpunct facet for the named locale
(class template)