GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::numpunct::grouping,std::numpunct::do_grouping(3) C++ Standard Libary std::numpunct::grouping,std::numpunct::do_grouping(3)

std::numpunct::grouping,std::numpunct::do_grouping - std::numpunct::grouping,std::numpunct::do_grouping


Defined in header <locale>
public: (1)
std::string grouping() const;
protected: (2)
virtual std::string do_grouping() const;


1) Public member function, calls the member function do_grouping of the most derived
class.
2) Returns an std::string holding, in each char element, the number of digits in
each group of the numeric output formatted by num_put::put() (and, therefore,
basic_ostream::operator<<)


The groups are stored as binary values: three-digit group is '\3', and 51-digit
group is '3'. The character at index zero of the returned string holds the number of
digits in the rightmost group. The character at index 1 holds the number of digits
in the second group from the right, etc. The grouping indicated by the last
character in the returned string is reused to group all remaining digits in the
(left part of) the number.


The object of type std::string holding the groups. The standard specializations of
std::numpunct return an empty string, indicating no grouping. Typical groupings
(e.g. the en_US locale) return "\003".

// Run this code


#include <iostream>
#include <limits>
#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
};


struct g123 : std::numpunct<char>
{
std::string do_grouping() const { return "\1\2\3"; }
};


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';
std::cout.imbue(std::locale(std::cout.getloc(), new g123));
std::cout << "Locale with \\1\\2\\3 grouping: " <<
std::numeric_limits<unsigned long long>::max() << '\n';
}


default locale: 12345678
locale with modified numpunct: 1 2 3 4 5 6 7 8
Locale with \1\2\3 grouping: 18,446,744,073,709,551,61,5


do_thousands_sep provides the character to use as thousands separator
[virtual] (virtual protected member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.