std::numpunct<CharT>:: decimal_point, do_decimal_point
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::decimal_point
numpunct::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