Namespaces
Variants

std:: moneypunct_byname

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

成员函数

(constructor)
构造新的 moneypunct_byname facet
(公开成员函数)
(destructor)
销毁 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 ) ;
(since C++11)

为具有 name 的区域设置构造新的 std::moneypunct_byname facet。

refs 用于资源管理:如果 refs == 0 ,当最后一个持有该 facet 的 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 [static] facet 的标识符
const bool intl [static] 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> 的虚受保护成员函数)
[virtual]
提供每对千位分隔符之间的数字位数
( 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 使用的货币格式化参数
(类模板)