std::moneypunct::pos_format
STD::货币区::pos[医]格式,做[医]pos[医]格式,neg[医]格式,做[医]内格[医]格式
Defined in header | | |
---|---|---|
public: pattern pos_format() const; | (1) | |
public: pattern neg_format() const; | (2) | |
protected: virtual pattern do_pos_format() const; | (3) | |
protected: virtual pattern do_neg_format() const; | (4) | |
1%29公共成员函数,调用成员函数do_pos_format
最派生的类。
2%29公共成员函数,调用成员函数do_neg_format
最派生的类。
3%29返回类型的格式结构%28std::money_base::format
%29,它描述了正货币值的格式。
4%29返回类型的格式结构%28std::money_base::format
%29,它描述了负货币值的格式。
标准专业std::moneypunct
返回模式{symbol, sign, none, value}
返回值
类型对象std::money_base::format
描述此区域设置所使用的格式。
例
二次
#include <locale>
#include <iostream>
#include <iomanip>
struct my_punct : std::moneypunct_byname<char, false> {
my_punct(const char* name) : moneypunct_byname(name) {}
pattern do_pos_format() const { return { {value, space, symbol, sign} };}
pattern do_neg_format() const { return { {value, space, symbol, sign} };}
};
int main()
{
std::cout.imbue(std::locale("en_US.utf8")
std::cout << "american locale: " << std::showbase
<< std::put_money(12345678.0) << '\n';
std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("en_US.utf8"))
std::cout << "locale with modified moneypunct:\n"
<< std::put_money(12345678.0) << '\n'
<< std::put_money(-12345678.0) << '\n';
}
二次
产出:
二次
american locale: $123,456.78
locale with modified moneypunct:
123,456.78 $
123,456.78 $-
二次
另见
do_curr_symbol virtual | provides the string to use as the currency identifier (virtual protected member function) |
---|---|
do_positive_signdo_negative_sign virtual | provides the string to indicate a positive or negative value (virtual protected member function) |
do_get virtual | parses a monetary value from an input stream (virtual protected member function of std::money_get) |
do_put virtual | formats a monetary value and writes to output stream (virtual protected member function of std::money_put) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。