std::moneypunct_byname
来自cppreference.com
在标头 <locale> 定义 | ||
template< class CharT, bool Intl = false > class moneypunct_byname : public std::moneypunct<CharT, Intl>; | ||
std::moneypunct_byname
是 std::moneypunct 刻面,封装在它构造时指定的本地环境的货币格式化偏好。
特化
标准库保证提供满足以下类型要求的所有特化:
CharT
是 char 或 wchar_tIntl
是 bool 形参可能的特化之一
嵌套类型
类型 | 定义 |
pattern | std::money_base::pattern |
string_type | std::basic_string<CharT> |
成员函数
(构造函数) | 构造新的 moneypunct_byname 刻面 (公开成员函数) |
(析构函数) | 销毁 moneypunct_byname 刻面 (受保护成员函数) |
std::moneypunct_byname::moneypunct_byname
explicit moneypunct_byname( const char* name, std::size_t refs = 0 ); | ||
explicit moneypunct_byname( const std::string& name, std::size_t refs = 0 ); | (C++11 起) | |
为名为 name 的本地环境构造新的 std::moneypunct_byname
刻面。
refs 用于资源管理:在销毁最后一个保有刻面的 std::locale 对象时,如果 refs == 0,那么实现会销毁刻面对象。否则不销毁对象。
参数
name | - | 本地环境的名称 |
refs | - | 链接到该刻面的引用数 |
std::moneypunct_byname::~moneypunct_byname
protected: ~moneypunct_byname(); | ||
销毁刻面。
继承自 std::moneypunct
嵌套类型
类型 | 定义 |
char_type | CharT |
string_type | std::basic_string<CharT> |
数据成员
成员 | 描述 |
std::locale::id id [静态] | 刻面标识 |
const bool intl [静态] | International |
成员函数
调用 do_decimal_point ( std::moneypunct<CharT,International> 的公开成员函数) | |
调用 do_thousands_sep ( std::moneypunct<CharT,International> 的公开成员函数) | |
调用 do_grouping ( std::moneypunct<CharT,International> 的公开成员函数) | |
调用 do_curr_symbol ( std::moneypunct<CharT,International> 的公开成员函数) | |
调用 do_positive_sign 或 do_negative_sign ( std::moneypunct<CharT,International> 的公开成员函数) | |
调用 do_frac_digits ( std::moneypunct<CharT,International> 的公开成员函数) | |
调用 do_pos_format /do_neg_format ( std::moneypunct<CharT,International> 的公开成员函数) |
受保护成员函数
提供用作小数点的字符 ( std::moneypunct<CharT,International> 的虚受保护成员函数) | |
提供用作千位分隔符的字符 ( std::moneypunct<CharT,International> 的虚受保护成员函数) | |
[虚] | 提供二个千位分隔符间的位数 ( std::moneypunct<CharT,International> 的虚受保护成员函数) |
提供用作通货标识符的字符串 ( std::moneypunct<CharT,International> 的虚受保护成员函数) | |
提供指示正或负值的字符串 ( std::moneypunct<CharT,International> 的虚受保护成员函数) | |
提供小数点后要显示的位数 ( std::moneypunct<CharT,International> 的虚受保护成员函数) | |
提供通货值的格式化模式 ( std::moneypunct<CharT,International> 的虚受保护成员函数) |
继承自 std::money_base
嵌套类型
类型 | 定义 |
enum part { none, space, symbol, sign, value }; | 无作用域枚举类型 |
struct pattern { char field[4]; }; | 货币格式类型 |
枚举常量 | 描述 |
none | 容许但不要求空白符,除了在末位置不容许空白符 |
space | 要求一或多个空白字符 |
symbol | 要求 std::moneypunct::curr_symbol 所返回的字符序列 |
sign | 要求 std::moneypunct::positive_sign 或 std::moneypunct::negative_sign 所返回的首个字符 |
value | 要求绝对数值货币值 |
示例
此示例演示如何应用另一语言的货币格式化规则而不更改本地环境的剩余部分。
运行此代码
#include <iomanip> #include <iostream> #include <locale> int main() { long double mon = 1234567; std::locale::global(std::locale("en_US.utf8")); std::wcout.imbue(std::locale()); std::wcout << L"美国本地环境:" << std::showbase << std::put_money(mon) << '\n'; std::wcout.imbue(std::locale(std::wcout.getloc(), new std::moneypunct_byname<wchar_t>("ru_RU.utf8"))); std::wcout << L"带有俄语货币格式的美国本地环境:" << std::put_money(mon) << '\n'; }
输出:
美国本地环境:$12,345.67 带有俄语货币格式的美国本地环境:12 345.67 руб
参阅
定义 std::money_get 与 std::money_put 所用的货币格式解析器的参数 (类模板) |