Namespaces
Variants
Views
Actions

std::numpunct

From cppreference.com
< cpp‎ | locale
Revision as of 01:29, 12 June 2012 by P12bot (Talk | contribs)

Template:cpp/locale/numpunct/sidebar Template:ddcl list begin <tr class="t-dsc-header">

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

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

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

<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.

Two specializations are provided by the standard library

Template:tdcl list headerTemplate:tdcl list itemTemplate:tdcl list item

Contents

Member types

Template:tdcl list hitemTemplate:tdcl list itemTemplate:tdcl list item

Member objects

Template:tdcl list hitemTemplate:tdcl list item

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 truenameTemplate:cpp/locale/numpunct/dcl list falsename

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 truenameTemplate:cpp/locale/numpunct/dcl list do falsename

Example

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';
}

Output:

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

See also

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