std::numpunct<CharT>:: thousands_sep, do_thousands_sep
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Localization library
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::numpunct
| Member functions | ||||
|
numpunct::thousands_sep
numpunct::do_thousands_sep
|
||||
|
定义于头文件
<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 ' '; } // 用空格分隔 std::string do_grouping() const { return "\1"; } // 每1位数字为一组 }; 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
|
参见
|
[virtual]
|
提供每对千位分隔符之间的数字位数
(虚受保护成员函数) |