std::moneypunct<CharT,International>::positive_sign, do_positive_sign, negative_sign, do_negative_sign
来自cppreference.com
| 在标头 <locale> 定义
|
||
| |
(1) | |
| |
(2) | |
| |
(3) | |
| |
(4) | |
1) 公开成员函数,调用最终派生类的成员函数
do_positive_sign。2) 公开成员函数,调用最终派生类的成员函数
do_negative_sign。3) 返回用作正货币值格式化的字符串。
3) 返回用作负货币值格式化的字符串。
只有返回字符串的首字符是出现于值 sign 所指示的 pos_format()/neg_format() 位置前的字符。剩下的字符出现在货币字符串的剩余部分之后'。
具体而言,对于 "-" 的 negative_sign,格式化可作为 "-1.23 €" 出现,而对于 "()" 的 negative_sign,它会作为 "(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() << " 负号是 '"
<< std::use_facet<std::moneypunct<char>>(loc).negative_sign()
<< "' 例如: " << std::showbase << std::put_money(-1234) << '\n';
std::locale loc2("ms_MY.utf8");
std::cout.imbue(loc2);
std::cout << loc2.name() << " 负号是 '"
<< std::use_facet<std::moneypunct<char>>(loc2).negative_sign()
<< "' 例如: " << std::put_money(-1234) << '\n';
std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("de_DE.utf8")));
std::cout << "de_DE.utf8 并将负号设为 \"()\": "
<< std::put_money(-1234) << '\n';
}
输出:
de_DE.utf8 负号是 '-' 例如: -12,34 €
ms_MY.utf8 负号是 '()' 例如: (RM12.34)
de_DE.utf8 并将负号设为 "()": (12,34 €)
参阅
| 提供通货值的格式化模式 (虚受保护成员函数) |