Namespaces
Variants
Views
Actions

std::numpunct::thousands_sep, std::numpunct::do_thousands_sep

From cppreference.com
< cpp‎ | locale‎ | numpunct
Revision as of 06:09, 23 April 2013 by P12 (Talk | contribs)

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

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

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

<td >
public:
char_type thousands_sep() const;
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
protected:
char_type virtual do_thousands_sep() const;
</td>

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

1) public member function, calls the member function do_thousands_sep of the most derived class.

2) returns the character to be used as the separator between digit groups when parsing or formatting integers and integral parts of floating-point values.

Return value

The object of type char_type to use as the thousands separator. The standard specializations of std::numpunct return ’,’ and L’,’.

Example

#include <iostream>
#include <locale>
 
struct space_out : std::numpunct<char> {
    char do_thousands_sep()   const { return ' '; }  // separate with spaces
    std::string do_grouping() const { return "\1"; } // groups of 1 digit
};
 
int main()
{
    std::cout << "default locale: " << 12345678 << '\n';
    std::cout.imbue(std::locale(std::cout.getloc(), new space_out));
    std::cout << "locale with modified numpunct: " << 12345678 << '\n';
}

Output:

default locale: 12345678
locale with modified numpunct: 1 2 3 4 5 6 7 8

See also

Template:cpp/locale/numpunct/dcl list do grouping