std::moneypunct<CharT,International>:: positive_sign, do_positive_sign, negative_sign, do_negative_sign
| 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 | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
moneypunct::positive_sign
moneypunct::do_positive_sign
moneypunct::negative_sign
moneypunct::do_negative_sign
|
||||
|
定义于头文件
<locale>
|
||
|
public
:
string_type positive_sign ( ) const ; |
(1) | |
|
public
:
string_type negative_sign ( ) const ; |
(2) | |
|
protected
:
virtual string_type do_positive_sign ( ) const ; |
(3) | |
|
protected
:
virtual string_type do_negative_sign ( ) const ; |
(4) | |
do_positive_sign
。
do_negative_sign
。
返回字符串中仅第一个字符会出现在由 pos_format() / neg_format() 的 sign 值所指示的位置。其余字符会出现在货币字符串的其余部分 之后 。
特别地,当负号标记为 "-" 时,格式化结果可能显示为 "-1.23 €" ;而当负号标记为 "()" 时,则会显示为 "(1.23 €)" 。
返回值
类型为
string_type
的字符串,用于存放将被用作正号或负号的字符。
示例
#include <iomanip> #include <iostream> #include <locale> struct my_punct : std::moneypunct_byname<char, false> { my_punct(const char* name) : moneypunct_byname(name) {} string_type do_negative_sign() const { return "()"; } }; int main() { std::locale loc("de_DE.utf8"); std::cout.imbue(loc); std::cout << loc.name() << " negative sign is '" << std::use_facet<std::moneypunct<char>>(loc).negative_sign() << "' for example: " << std::showbase << std::put_money(-1234) << '\n'; std::locale loc2("ms_MY.utf8"); std::cout.imbue(loc2); std::cout << loc2.name() << " negative sign is '" << std::use_facet<std::moneypunct<char>>(loc2).negative_sign() << "' for example: " << std::put_money(-1234) << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("de_DE.utf8"))); std::cout << "de_DE.utf8 with negative_sign set to \"()\": " << std::put_money(-1234) << '\n'; }
输出:
de_DE.utf8 negative sign is '-' for example: -12,34 € ms_MY.utf8 negative sign is '()' for example: (RM12.34) de_DE.utf8 with negative_sign set to "()": (12,34 €)
参见
|
[virtual]
|
提供货币值的格式化模式
(虚受保护成员函数) |