命名空间
变体
操作

std::numpunct<CharT>::thousands_sep, do_thousands_sep

来自 cppreference.cn
< cpp‎ | locale‎ | numpunct
 
 
 
 
 
定义于头文件 <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

[编辑] 参阅

提供每对千位分隔符之间的数字个数
(虚保护成员函数) [编辑]