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 平面,封装在其构造时指定的 locale 的货币格式化偏好。
标准库提供二个特化
|   定义于头文件  
<locale>  | |
| std::moneypunct_byname<char, Intl> | 窄字符 I/O 的本地环境限定 std::moneypunct 平面 | 
| std::moneypunct_byname<wchar_t, Intl> | 宽字符 I/O 的本地环境限定 std::moneypunct 平面 | 
成员类型
| 成员类型 | 定义 | 
  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> | 
成员函数
  调用 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> 的虚受保护成员函数)  | 
成员常量
| 成员 | 定义 | 
  const bool intl [静态]
 | 
  International
 | 
成员对象
|    static std::locale::id id  | 
  locale 的 id  (公开成员对象)  | 
继承自 std::money_base
| 成员类型 | 定义 | 
| enum part { none, space, symbol, sign, value }; | 无作用域枚举类型 | 
| struct pattern { char field[4]; }; | 货币格式类型 | 
| 枚举常量 | 解释 | 
  none
 | 
容许但不要求空白符,除了在末位置不容许空白符 | 
  space
 | 
要求一或多个空白字符 | 
  symbol
 | 
要求 moneypunct::curr_symbol 所返回的字符序列 | 
  sign
 | 
要求 moneypunct::positive_sign 或 moneypunct::negative_sign 所返回的首个字符 | 
  value
 | 
要求绝对数值货币值 | 
示例
此示例演示如何应用另一语言的货币格式化规则而不更改 locale 的剩余部分。
运行此代码
#include <iostream> #include <iomanip> #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 所用的货币格式解析器的参数  (类模板)  |