std::moneypunct<CharT,International>::curr_symbol, do_curr_symbol
来自 cppreference.cn
< cpp | locale | moneypunct
定义于头文件 <locale> |
||
public: string_type curr_symbol() const; |
(1) | |
protected: virtual string_type do_curr_symbol() const; |
(2) | |
1) 公有成员函数,调用最派生类的成员函数
do_curr_symbol
。2) 返回此区域设置所使用的货币标识符字符串。如果
International
(std::moneypunct
的第二个模板参数) 为 false,则标识符通常为单个(宽)字符,例如 "¥" 或 "$"。如果 International
为 true,则标识符通常是包含三字符 ISO 4217 货币代码后跟一个空格的四字符字符串("JPY " 或 "USD ")。目录 |
[edit] 返回值
类型为 string_type
的对象,持有货币符号或代码。
[edit] 示例
运行此代码
#include <iostream> #include <locale> void show_ccy(const char* locname) { std::locale loc(locname); std::cout << locname << " currency symbol is " << std::use_facet<std::moneypunct<char, true>>(loc).curr_symbol() << "or " << std::use_facet<std::moneypunct<char>>(loc).curr_symbol() << " for short\n"; } int main() { show_ccy("en_US.utf8"); show_ccy("ja_JP.utf8"); show_ccy("sv_SE.utf8"); show_ccy("ru_RU.utf8"); show_ccy("vi_VN.utf8"); }
输出
en_US.utf8 currency symbol is USD or $ for short ja_JP.utf8 currency symbol is JPY or ¥ for short sv_SE.utf8 currency symbol is SEK or kr for short ru_RU.utf8 currency symbol is RUB or руб for short vi_VN.utf8 currency symbol is VND or ₫ for short
[edit] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 666 | C++98 | 如果 International 为 true,则标识符字符串的长度必须为 4 |
非必需 |
[edit] 参见
提供货币值的格式化模式 (虚保护成员函数) |