public member function
<locale>

std::numpunct::grouping

string grouping() const;
數字分組
返回一個指示每個分組中數字數量的序列。

該序列以 stringbasic_string<char>)的形式返回,其中每個 char 元素都應解釋為表示每個分組中數字數量的整數值。分組是從右到左考慮的,字串中的第一個字元用於最右邊的組,最後一個字元用於比字串長度更遠的任何組。

例如,"\03" 表示每組三個數字,而 "\02\03" 表示最右邊的組有兩個數字,其餘的組都各有三個數字。

在內部,此函式僅呼叫受保護的虛成員 do_grouping,該函式預設返回 "C" 區域設定的值:一個空字串,表示不分組。

引數



返回值

表示從右到左的數字分組值的字串。
負值或等於 CHAR_MAX 的值表示組中的數字數量不限。
返回的空字串表示不分組。
請注意,無論用作模板引數 charT 的字元型別是什麼,這都是一個 basic_string<char> 型別的物件。

示例

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

輸出

one million: 1,000,000


資料競爭

訪問此分面。

異常安全

強異常保證: 如果丟擲異常,則沒有副作用。

另見