命名空间
变体
操作

std::moneypunct_byname

来自 cppreference.cn
< cpp‎ | locale
 
 
 
 
定义于头文件 <locale>
template< class CharT, bool Intl = false >
class moneypunct_byname : public std::moneypunct<CharT, Intl>;

std::moneypunct_byname 是一个 std::moneypunct 面(facet),它封装了在构造时指定区域设置(locale)的货币格式偏好。

目录

[编辑] 特化

标准库保证提供满足以下类型要求的每种特化

  • CharTcharwchar_t 之一,并且
  • Intlbool 参数的一种可能特化。

[编辑] 嵌套类型

类型 定义
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 用于资源管理:如果 refs == 0,则当最后一个持有它的 std::locale 对象被销毁时,实现会销毁该面。否则,对象不会被销毁。

参数

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 [static] facet 的标识符
const bool intl [static] 国际

成员函数

调用 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_signdo_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]; }; 货币格式类型
枚举常量 描述
允许但不强制要求空格,除了在最后一个位置,该位置不允许有空格
space 需要一个或多个空格字符
symbol 要求 std::moneypunct::curr_symbol 返回的字符序列
sign 要求 std::moneypunct::positive_signstd::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_getstd::money_put 使用的货币格式参数
(类模板) [编辑]