std::numpunct<CharT>::thousands_sep, do_thousands_sep
來自 cppreference.com
定義於標頭檔案 <locale> |
||
public: char_type thousands_sep() const; |
(1) | |
protected: virtual char_type do_thousands_sep() const; |
(2) | |
1) 公有成員函式,呼叫最派生類的成員函式
do_thousands_sep
。2) 返回用於解析或格式化整數及浮點數整數部分時,數字組之間的分隔符。
目錄 |
[編輯] 返回值
用作千位分隔符的 char_type
型別物件。 std::numpunct
的標準特化返回 ',' 和 L','。
[編輯] 示例
執行此程式碼
#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'; }
輸出
default locale: 12345678 locale with modified numpunct: 1 2 3 4 5 6 7 8
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 20 | C++98 | 返回型別是 string_type |
改為 char_type |
[編輯] 參閱
[虛] |
提供每對千位分隔符之間的數字個數 (虛保護成員函式) |