std::num_put_C++中文网
类 std::num_put 封装格式化数值为字符串的规则。具体而言支持 bool 、 long 、 unsigned long 、 long long 、 unsigned long long 、 double 、 long double 、 void* 类型和所有能隐式转换到它们的类型(例如 int 或 float )。标准格式化输出运算符(如 cout << n; )用 I/O 流的 locale 的 std::num_put 平面生成数字的文本表示。
继承图
类型要求
特化
标准库提供二个孤立(独立于本地环境)的全特化和二个部分特化:
| 定义于头文件 | |
| std::num_put<char> | 创建数的窄字符串表示 |
| std::num_put<wchar_t> | 创建数的宽字符串表示 |
| std::num_put<char, OutputIt> | 用定制输出迭代器创建数的窄字符串表示 |
| std::num_put<wchar_t, OutputIt> | 用定制输出迭代器创建数的宽字符串表示 |
另外, C++ 程序中构造的每个 locale 对象都实装这些特化的其自身(本地环境限定)版本。
成员类型
| 成员类型 | 定义 |
char_type
|
CharT
|
iter_type
|
OutputIt
|
成员函数
| 构造新的 num_put 平面 (公开成员函数) | |
| 销毁 num_put 平面 (受保护成员函数) | |
调用 do_put (公开成员函数) |
受保护成员函数
| 格式化数字并写入到输出流 (虚受保护成员函数) |
成员对象
| static std::locale::id id |
locale 的 id (公开成员对象) |
示例
输出:
Direct conversion to string: 1234567.890000 Output using a german locale: 1.234.567,890000 Output using an american locale: 1,234,567.890000