名前空間
変種
操作

std::put_money

From cppreference.com
< cpp‎ | io‎ | manip
 
 
 
入出力マニピュレータ
浮動小数点フォーマット
整数フォーマット
boolフォーマット
フィールド幅と埋め文字制御
その他のフォーマット
空白文字の処理
出力のフラッシュ
(C++20)  

ステータスフラグの操作
時間と通貨のI/O
(C++11)
(C++11)
put_money
(C++11)
(C++11)
クォート付きマニピュレータ
(C++14)
 
ヘッダ<iomanip>で定義
template< class MoneyT >
/*unspecified*/ put_money( const MoneyT& mon, bool intl = false );
(C++11以降)

out << put_money(mon, intl) という式で使用されると、現在 out に設定されているロケールの std::money_put ファセットによって指定された文字列表現に、貨幣値 mon を変換します。

out << put_money(mon, intl) の挿入操作は、FormattedOutputFunction として機能します。

目次

[edit] Parameters

mon - long double または std::basic_string のいずれかの貨幣値
intl - 真の場合、国際通貨記号を使用します。それ以外の場合は、通貨記号を使用します。

[edit] Return value

未指定の型のオブジェクト。その結果、

ここで関数 f は次のように定義されます。

template<class CharT, class Traits, class MoneyT>
void f(std::basic_ios<CharT, Traits>& str, const MoneyT& mon, bool intl)
{
    using Iter = std::ostreambuf_iterator<CharT, Traits>;
    using MoneyPut = std::money_put<CharT, Iter>;
 
    const MoneyPut& mp = std::use_facet<MoneyPut>(str.getloc());
    const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);
 
    if (end.failed())
        str.setstate(std::ios_base::badbit);
}

[edit] Example

#include <iomanip>
#include <iostream>
 
int main()
{
    long double mon = 123.45; // or std::string mon = "123.45";
 
    std::cout.imbue(std::locale("en_US.UTF-8"));
    std::cout << std::showbase
              << "en_US: " << std::put_money(mon)
              << " or " << std::put_money(mon, true) << '\n';
 
    std::cout.imbue(std::locale("ru_RU.UTF-8"));
    std::cout << "ru_RU: " << std::put_money(mon)
              << " or " << std::put_money(mon, true) << '\n';
 
    std::cout.imbue(std::locale("ja_JP.UTF-8"));
    std::cout << "ja_JP: " << std::put_money(mon)
              << " or " << std::put_money(mon, true) << '\n';
}

実行結果の例

en_US: $1.23 or USD  1.23
ru_RU: 1.23 руб or 1.23 RUB 
ja_JP: ¥123 or JPY  123

[edit] See also

通貨値を文字列シーケンスとして出力するために書式設定する
(クラステンプレート) [編集]
(C++11)
通貨の値を構文解析する
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)