std::money_put<CharT,OutputIt>:: put, do_put
|
定義済みヘッダー
<locale>
|
||
|
public
:
iter_type put
(
iter_type out,
bool
intl,
std::
ios_base
&
f,
|
(1) | |
|
iter_type put
(
iter_type out,
bool
intl,
std::
ios_base
&
f,
char_type fill, const string_type & quant ) const ; |
(2) | |
|
protected
:
virtual
iter_type do_put
(
iter_type out,
bool
intl,
std::
ios_base
&
str,
|
(3) | |
|
virtual
iter_type do_put
(
iter_type out,
bool
intl,
std::
ios_base
&
str,
char_type fill, const string_type & digits ) const ; |
(4) | |
金額の値をフォーマットし、結果を出力ストリームに書き込みます。
do_put
を呼び出す。
前のステップからの文字シーケンスが与えられた場合、最初の文字が ct. widen ( '-' ) と等しい場合、 mp. neg_format ( ) を呼び出して書式 パターン を取得し、それ以外の場合は mp. pos_format ( ) を呼び出します。ここで mp は std:: moneypunct < CharT, intl > ファセットであり、 str. getloc ( ) にimbueされています。
桁区切り文字と小数点文字は、 mp. grouping ( ) 、 mp. frac_digits ( ) 、 mp. decimal_point ( ) および mp. thousands_sep ( ) によって要求される通りに挿入され、結果の文字列は書式パターン内で value が現れる位置に出力シーケンスに配置されます。
str. flags ( ) & str. showbase が非ゼロの場合( std::showbase マニピュレータが使用された場合)、通貨記号または文字列は mp. curr_symbol ( ) を呼び出すことで生成され、フォーマットパターン内の symbol が現れる位置に出力シーケンスに配置されます。
positive format pattern(正のフォーマットパターンが使用される場合)で mp. positive_sign ( ) が、またはnegative format pattern(負のフォーマットパターンが使用される場合)で mp. negative_sign ( ) が複数文字の文字列を返す場合、返される最初の文字はフォーマットパターン内の sign が現れる位置に出力シーケンスに配置され、残りの文字は他のすべての文字の後に配置されます。例えば、フォーマットパターン { sign, value, space, symbol } で単位 123 とnegative_signが "-" の場合、 "-1.23 €" という結果になる可能性がありますが、negative_signが "()" の場合、 "(1.23 €)" が生成されます。
指定されたフォーマットで生成される文字数が str. width ( ) によって返される値より少ない場合、 fill のコピーが挿入され、出力シーケンスの全長が正確に str. width ( ) になるように調整されます。具体的には以下の通りです:
-
str.
flags
(
)
&
str.
adjustfield
が
str.
internal
と等しい場合、フィル文字は書式パターン内の
noneまたはspaceが現れる位置に挿入されます。 - それ以外の場合、 str. flags ( ) & str. adjustfield が str. left と等しい場合、 fill のコピーが他のすべての文字の後に追加されます。
- それ以外の場合、フィル文字は他のすべての文字の前に配置されます。
最終的に、 str. width ( 0 ) を呼び出して、あらゆる std::setw の効果をキャンセルします。
目次 |
戻り値
生成された最後の文字の直後を指すイテレータ。
注記
通貨単位は、通貨の最小の非分数単位と見なされます:米国ではセント、日本では円。
例
#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("ru_RU.utf8"); std::cout.imbue(loc); long double units = -123.45; std::cout << "In Russian locale, " << units << " prints as " << std::showbase; // note, the following is equivalent to simply std::put_money(units) std::use_facet<std::money_put<char>>(loc).put( {std::cout}, false, std::cout, std::cout.fill(), units); std::cout << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("ru_RU.utf8"))); std::cout << "With negative_sign set to \"()\", it prints as "; std::use_facet<std::money_put<char>>(loc).put( {std::cout}, false, std::cout, std::cout.fill(), units); std::cout << '\n'; }
出力:
In Russian locale, -123,45 prints as -1.23 руб With negative_sign set to "()", it prints as (1.23 руб)
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 328 | C++98 | std::sprintf で使用されるフォーマット文字列は "%.01f" であった | "%.0Lf" に修正された |
関連項目
|
std::money_get
および
std::money_put
で使用される通貨書式パラメータを定義する
(クラステンプレート) |
|
|
入力文字シーケンスから通貨値を解析および構築する
(クラステンプレート) |
|
|
(C++11)
|
通貨値を書式設定して出力する
(関数テンプレート) |