Namespaces
Variants

std::moneypunct<CharT,International>:: curr_symbol, do_curr_symbol

From cppreference.net
定义于头文件 <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 " )。

目录

返回值

类型为 string_type 的对象,用于保存货币符号或代码。

示例

#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

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时行为 正确行为
LWG 666 C++98 International true 时,要求标识符字符串的长度必须为 4 不作要求

参见

提供货币值的格式化模式
(虚受保护成员函数)