std::numpunct<CharT>::thousands_sep, do_thousands_sep
来自 cppreference.cn
定义于头文件 <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++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 20 | C++98 | 返回类型为 string_type |
更改为 char_type |
[编辑] 参见
[虚拟] |
提供每对千位分隔符之间的位数 (虚拟保护成员函数) |