Namespaces
Variants

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

From cppreference.net
ヘッダーで定義 <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の標準特殊化はパターン std:: moneypunct を返します { symbol, sign, none, value }

目次

戻り値

このロケールで使用される書式を記述する std::money_base::format 型のオブジェクト。

注記

std::money_put が正の値のフォーマットに pos_format を、負の値のフォーマットに neg_format を使用するのに対し、 std::money_get はすべての通貨値のパースに neg_format を使用します:これは neg_format pos_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 メンバー関数)
[virtual]
入力ストリームから通貨値を解析する
( std::money_get<CharT,InputIt> の仮想 protected メンバー関数)
[virtual]
通貨値をフォーマットして出力ストリームに書き込む
( std::money_put<CharT,OutputIt> の仮想 protected メンバー関数)