名前空間
変種
操作

std::moneypunct<CharT,International>::positive_sign、do_positive_sign、negative_sign、do_negative_sign

From cppreference.com
< cpp‎ | locale‎ | moneypunct
 
 
 
 
 
ヘッダー <locale> で定義
public:
string_type positive_sign() const;
(1)
public:
string_type negative_sign() const;
(2)
protected:
virtual string_type do_positive_sign() const;
(3)
protected:
virtual string_type do_negative_sign() const;
(4)
1) 最も派生したクラスのメンバ関数do_positive_signを呼び出す、公開メンバ関数です。
2) 最も派生したクラスのメンバ関数do_negative_signを呼び出す、公開メンバ関数です。
3) 正の通貨値をフォーマットするために使用される文字列を返します。
3) 負の通貨値をフォーマットするために使用される文字列を返します。

返される文字列の最初の文字のみが、pos_format()/neg_format()signの値によって示される位置に表示される文字です。残りの文字は、通貨文字列の残りの部分のに表示されます。

特に、"-"のnegative_signの場合、フォーマットは"-1.23 €"のように表示される可能性がありますが、"()"のnegative_signの場合は"(1.23 €)"のように表示されます。

[編集] 戻り値

正または負の記号として使用される文字を保持するstring_type型の文字列。

[編集]

#include <iomanip>
#include <iostream>
#include <locale>
 
struct my_punct : std::moneypunct_byname<char, false>
{
    my_punct(const char* name) : moneypunct_byname(name) {}
    string_type do_negative_sign() const { return "()"; }
};
 
int main()
{
    std::locale loc("de_DE.utf8");
    std::cout.imbue(loc);
    std::cout << loc.name() << " negative sign is '"
              << std::use_facet<std::moneypunct<char>>(loc).negative_sign()
              << "' for example: " << std::showbase << std::put_money(-1234) << '\n';
 
    std::locale loc2("ms_MY.utf8");
    std::cout.imbue(loc2);
    std::cout << loc2.name() << " negative sign is '"
              << std::use_facet<std::moneypunct<char>>(loc2).negative_sign()
              << "' for example: " << std::put_money(-1234) << '\n';
 
    std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("de_DE.utf8")));
    std::cout << "de_DE.utf8 with negative_sign set to \"()\": "
              << std::put_money(-1234) << '\n';
}

出力

de_DE.utf8 negative sign is '-' for example: -12,34 €
ms_MY.utf8 negative sign is '()' for example: (RM12.34)
de_DE.utf8 with negative_sign set to "()": (12,34 €)

[編集] 関連項目

通貨値の書式設定パターンを提供します。
(virtual protected member function) [編集]
English 日本語 中文(简体) 中文(繁體)