std::numpunct<CharT>::decimal_point, do_decimal_point
来自cppreference.com
本地化库
本地环境与平面 | |||||||||||||||||||||
本地环境 | |||||||||||||||||||||
平面类别基类 | |||||||||||||||||||||
ctype(字符类别)平面 | |||||||||||||||||||||
numeric(数值)平面 | |||||||||||||||||||||
collate(对照比较)平面 | |||||||||||||||||||||
time(时间)平面 | |||||||||||||||||||||
monetary(货币)平面 | |||||||||||||||||||||
messages(消息)平面 | |||||||||||||||||||||
字符分类与转换 | |||||||||||||||||||||
字符分类 | |||||||||||||||||||||
转换 | |||||||||||||||||||||
|
|||||||||||||||||||||
编码转换平面 | |||||||||||||||||||||
|
|
||||||||||||||||||||
C 本地环境 | |||||||||||||||||||||
std::numpunct
成员函数 | ||||
numpunct::decimal_pointnumpunct::do_decimal_point
|
||||
在标头
<locale>
定义
|
||
public:
char_type decimal_point() const; |
(1) | |
protected:
virtual char_type do_decimal_point() const; |
(2) | |
1) 公开成员函数,调用最终导出类的成员函数
do_decimal_point
。
2) 返回要用作整数和小数部分间的小数分隔符的字符。
返回值
用作小数分隔符的 char_type
类型值。 std::numpunct
的标准特化返回 '.' 和 L'.' 。
示例
运行此代码
#include <iostream> #include <locale> struct slash : std::numpunct<char> { char do_decimal_point() const { return '/'; } // 以斜杠分隔 }; int main() { std::cout.precision(10); std::cout << "default locale: " << 1234.5678 << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new slash)); std::cout << "locale with modified numpunct: " << 1234.5678 << '\n'; }
输出:
default locale: 1234.5678 locale with modified numpunct: 1234/5678