std::moneypunct_byname
来自 cppreference.cn
定义于头文件 <locale> |
||
template< class CharT, bool Intl = false > class moneypunct_byname : public std::moneypunct<CharT, Intl>; |
||
std::moneypunct_byname
是一个 std::moneypunct facet,它封装了在其构造时指定的区域设置的货币格式化偏好。
目录 |
[编辑] 特化
标准库保证提供满足以下类型要求的每个特化
-
CharT
是 char 和 wchar_t 之一,并且 -
Intl
是 bool 参数上可能的特化。
[编辑] 嵌套类型
类型 | 定义 |
pattern
|
std::money_base::pattern |
string_type
|
std::basic_string<CharT> |
[编辑] 成员函数
(构造函数) |
构造一个新的 moneypunct_byname facet(公共成员函数) |
(析构函数) |
销毁一个 moneypunct_byname facet(受保护的成员函数) |
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
facet。
refs 用于资源管理:如果 refs == 0,则当最后一个持有它的 std::locale 对象被销毁时,实现会销毁该 facet。否则,该对象不会被销毁。
参数
name | - | 区域设置的名称 |
refs | - | 链接到 facet 的引用数 |
std::moneypunct_byname::~moneypunct_byname
protected: ~moneypunct_byname(); |
||
销毁 facet。
继承自 std::moneypunct
嵌套类型
类型 | 定义 |
char_type
|
CharT
|
string_type
|
std::basic_string<CharT> |
数据成员
成员 | 描述 |
std::locale::id id [静态] |
facet 的标识符 |
const bool intl [静态] |
国际化 |
成员函数
调用 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"american locale: " << 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"american locale with russian moneypunct: " << std::put_money(mon) << '\n'; }
输出
american locale: $12,345.67 american locale with russian moneypunct: 12 345.67 руб
[编辑] 参见
定义 std::money_get 和 std::money_put 使用的货币格式化参数 (类模板) |