首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::numpunct

Defined in header <locale>

?

?

template< class CharT > class numpunct;

?

?

std::numpunct封装数字标点符号首选项。流I/O操作使用std::numpunctstd::num_getstd::num_put用于解析数字输入和格式化数字输出。

支持的数字std::numpunct格式如下。在这里digit表示由fmtflags参数值,thousands-sepdecimal-pointthousands_sep()decimal_point()分别函数。整数值的格式如下:

二次

代码语言:javascript
复制
integer     ::= [sign] units
sign        ::= plusminus
plusminus   ::= '+' | '-'
units       ::= digits [thousands-sep units]
digits      ::= digit [digits]

二次

之间的位数。thousand-sepS%28最大尺寸digits%29由grouping()...

浮点值的格式如下:

二次

代码语言:javascript
复制
floatval    ::= [sign] units [decimal-point [digits]] [e [sign] digits] |
                [sign]        decimal-point  digits   [e [sign] digits]
e           ::= ’e’ | ’E’

二次

二次

二次

继承图

标准库提供了两个独立的%28区域设置无关%29的专门化:

在标头中定义<locale>

*。

性传播疾病:无刺<char>提供“C”区域设置首选项的等效项。

STD::num点t<wchar[医]T>提供“C”区域设置首选项的宽字符等价物

此外,在C++程序中构造的每个locale对象都实现了自己的%28 locale特定于这些专门化的%29版本。

成员类型

Member type

Definition

char_type

charT

string_type

std::basic_string<charT>

成员函数

(constructor)

constructs a new numpunct facet (public member function)

(destructor)

destructs a numpunct facet (protected member function)

二次

十进制[医]点调用[医]十进制[医]点%28公共成员功能%29

千[医]九月调用[医]千[医]9%28公众成员功能%29

分组调用[医]分组%28公共成员功能%29

真花椒调用do[医]真实名称或行为[医]法尔塞纳%28公共成员功能%29

受保护成员函数

do_decimal_point virtual

provides the character to use as decimal point (virtual protected member function)

do_thousands_sep virtual

provides the character to use as thousands separator (virtual protected member function)

do_grouping virtual

provides the numbers of digits between each pair of thousands separators (virtual protected member function)

do_truenamedo_falsename virtual

provides the string to use as the name of the boolean true and false (virtual protected member function)

成员对象

static std::locale::id id

id of the locale (public member object)

下面的示例更改truefalse...

二次

代码语言:javascript
复制
#include <iostream>
#include <locale>
 
struct french_bool : std::numpunct<char> {
    string_type do_truename() const { return "oui"; }
    string_type do_falsename() const { return "non"; }
};
 
int main()
{
    std::cout << "default locale: "
              << std::boolalpha << true << ", " << false << '\n';
    std::cout.imbue(std::locale(std::cout.getloc(), new french_bool));
    std::cout << "locale with modified numpunct: "
              << std::boolalpha << true << ", " << false << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
default locale: true, false
locale with modified numpunct: oui, non

二次

另见

numpunct_byname

creates a numpunct facet for the named locale (class template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com