命名空间
变体
操作

std::moneypunct<CharT,International>::pos_format, do_pos_format, neg_format, do_neg_format

来自 cppreference.cn
< cpp‎ | locale‎ | moneypunct
 
 
 
 
 
定义于头文件 <locale>
public:
pattern pos_format() const;
(1)
public:
pattern neg_format() const;
(2)
protected:
virtual pattern do_pos_format() const;
(3)
protected:
virtual pattern do_neg_format() const;
(4)
1) 公有成员函数,调用最派生类的成员函数 do_pos_format
2) 公有成员函数,调用最派生类的成员函数 do_neg_format
3) 返回格式结构(类型为 std::money_base::format),描述正货币值的格式化。
4) 返回格式结构(类型为 std::money_base::format),描述负货币值的格式化。

std::moneypunct 的标准特化返回模式 {symbol, sign, none, value}

内容

[编辑] 返回值

类型为 std::money_base::format 的对象,描述由此区域设置所用的格式化。

[编辑] 注解

std::money_put 使用 pos_format 格式化正值,而 neg_format 格式化负值,std::money_get 为解析所有货币值而使用 neg_format:它假定 neg_formatpos_format 兼容。

[编辑] 示例

#include <iomanip>
#include <iostream>
#include <locale>
 
struct my_punct : std::moneypunct_byname<char, false>
{
    my_punct(const char* name) : moneypunct_byname(name) {}
    pattern do_pos_format() const { return {value, space, symbol, sign}; }
    pattern do_neg_format() const { return {value, space, symbol, sign}; }
};
 
int main()
{
    std::cout.imbue(std::locale("en_US.utf8"));
    std::cout << "american locale: " << std::showbase
              << std::put_money(12345678.0) << '\n';
 
    std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("en_US.utf8")));
    std::cout << "locale with modified moneypunct:\n"
              << std::put_money(12345678.0) << '\n'
              << std::put_money(-12345678.0) << '\n';
}

输出

american locale: $123,456.78
locale with modified moneypunct:
123,456.78 $
123,456.78 $-

[编辑] 参见

[虚函数]
提供用作货币标识符的字符串
(虚函数 protected 成员函数) [编辑]
提供指示正值或负值的字符串
(虚函数 protected 成员函数) [编辑]
[虚函数]
从输入流解析货币值
(std::money_get<CharT,InputIt> 的虚函数 protected 成员函数) [编辑]
[虚函数]
格式化货币值并写入到输出流
(std::money_put<CharT,OutputIt> 的虚函数 protected 成员函数) [编辑]