public member function
<locale>

std::numpunct::grouping

string grouping() const;
Grouping of digits
Returns a sequence of values indicating the number of digits in each group.

The sequence is returned as a string (basic_string<char>) where each char element shall be interpreted as an integer value indicating the number of digits in each group. Grouping is considered from right to left, with the first character in the string being used for the rightmost group, and the last character used for any group farther away than the length of the string.

For example, "\03" indicates groups of three digits each, while "\02\03" would indicate that the rightmost group has two digits and all the remaining ones have three digits each.

Internally, this function simply calls the virtual protected member do_grouping, which by default returns the value returned for the "C" locale: an empty string, indicating no grouping.

Parameters

none

Return value

A string containing a sequence of digit grouping values, from right to left.
Negative values, or values equal to CHAR_MAX, indicate that the number of digits in the group is unlimited.
An empty string as returned value indicates no grouping.
Notice that this is an object of type basic_string<char> no matter what character type is used as template parameter charT.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// numpunct::grouping example
#include <iostream>       // std::cout
#include <string>         // std::string
#include <locale>         // std::locale, std::numpunct, std::use_facet

// custom numpunct with grouping:
struct my_numpunct : std::numpunct<char> {
  std::string do_grouping() const {return "\03";}
};

int main() {
  std::locale loc (std::cout.getloc(),new my_numpunct);
  std::cout.imbue(loc);
  std::cout << "one million: " << 1000000 << '\n';
  return 0;
}

Output:

one million: 1,000,000


Data races

The facet is accessed.

Exception safety

Strong guarantee: No side effects in case an exception is thrown.

See also