std:: put_money
|
ヘッダーで定義
<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 | - | 通貨値、 long double または std::basic_string |
| intl | - | true の場合、国際通貨文字列を使用、それ以外の場合は通貨記号を使用 |
戻り値
未指定の型のオブジェクトであり、以下の条件を満たすもの
-
outが型 std:: basic_ostream < CharT, Traits > のオブジェクトである場合、式 out << put_money ( mon, intl )- 型は std:: basic_ostream < CharT, Traits > & を持つ
- 値は out を持つ
- FormattedOutputFunction として振る舞い、 f ( out, mon, intl ) を呼び出す
関数 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); }
例
#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
関連項目
|
通貨値を文字シーケンスとして出力するためにフォーマットする
(クラステンプレート) |
|
|
(C++11)
|
通貨値を解析する
(関数テンプレート) |