std::put_money
提供: cppreference.com
ヘッダ <iomanip> で定義 | ||
template<class MoneyT > /*unspecified*/ put_money(const MoneyT& mon, bool intl =false); | (C++11以上) | |
式 out << put_money(mon, intl) で使用されたとき、金額値 mon
を out
に現在設定されているロケールの std::money_put ファセットによって指定される文字表現に変換します。
out << put_money(mon, intl) の挿入操作は FormattedOutputFunction として動作します。
目次 |
[編集]引数
mon | - | 金額値、 longdouble または std::basic_string のいずれか |
intl | - | true の場合は国際通貨文字列を使用し、そうでなければ通貨記号を使用します |
[編集]戻り値
out
が std::basic_ostream<CharT, Traits> 型の出力ストリームの名前である場合に式 out << put_money(mon, intl) が以下のコードが実行されたかのように動作するような、未規定な型のオブジェクトを返します。
typedefstd::ostreambuf_iterator<CharT, Traits> Iter;
typedefstd::money_put<CharT, Iter> MoneyPut;
const MoneyPut& mp =std::use_facet<MoneyPut>(out.getloc());
const Iter end = mp.put(Iter(out.rdbuf()), intl, out, out.fill(), mon);
if(end.failed())
out.setstate(std::ios::badbit);
[編集]例
Run this code
#include <iostream>#include <iomanip> int main(){longdouble mon =123.45;// or std::string mon = "123.45"; std::cout.imbue(std::locale("en_US.utf8"));std::cout<<std::showbase<<"en_US: "<< std::put_money(mon)<<" or "<< std::put_money(mon, true)<<'\n'; std::cout.imbue(std::locale("ru_RU.utf8"));std::cout<<"ru_RU: "<< std::put_money(mon)<<" or "<< std::put_money(mon, true)<<'\n'; std::cout.imbue(std::locale("ja_JP.utf8"));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
[編集]関連項目
文字シーケンスとして出力するために金額の値をフォーマットします (クラステンプレート) | |
(C++11) | 金額をパースします (関数テンプレート) |