std::numpunct
From cppreference.com
| ヘッダー <locale> で定義 |
||
| template< class CharT > class numpunct; |
||
std::numpunct ファセットは、数値の句読点の好みをカプセル化します。ストリーム I/O 操作は、数値入力の解析と数値出力のフォーマットのために、std::num_get および std::num_put を介して std::numpunct を使用します。
std::numpunct によってサポートされる数値は、以下に説明する形式を持ちます。ここで digit は fmtflags 引数値によって指定される基数セットを表し、thousands-sep および decimal-point はそれぞれ thousands_sep() および decimal_point() 関数の結果です。
整数値の形式は次のとおりです。
integer ::= [sign] units sign ::= plusminus plusminus ::= '+' | '-' units ::= digits [thousands-sep units] digits ::= digit [digits]
thousand-sep 間の桁数(digits の最大サイズ)は、grouping() の結果によって指定されます。
浮動小数点値の形式は次のとおりです。
floatval ::= [sign] units [decimal-point [digits]] [e [sign] digits] |
[sign] decimal-point digits [e [sign] digits]
e ::= 'e' | 'E'継承図
目次 |
[編集] 特殊化
標準ライブラリは、以下の特殊化を提供することが保証されています(これらは あらゆるロケールオブジェクトによって実装される必要があります)。
| ヘッダー
<locale> で定義 | |
| std::numpunct<char> | 「C」ロケールの好みに相当するものを提供します。 |
| std::numpunct<wchar_t> | 「C」ロケールの好みのワイド文字相当のものを提供します。 |
[編集] ネストされた型
| 型 | 定義 |
char_type
|
CharT
|
string_type
|
std::basic_string<CharT> |
[編集] データメンバ
| メンバ | 説明 |
std::locale::id id [static] |
ファセットの識別子 |
[編集] メンバ関数
新しい numpunct ファセットを構築します。(public member function) | |
numpunct ファセットを破棄します。(protected member function) | |
do_decimal_point を呼び出します。(public member function) | |
do_thousands_sep を呼び出します。(public member function) | |
do_grouping を呼び出します。(public member function) | |
do_truename または do_falsename を呼び出します。(public member function) |
[編集] 保護されたメンバ関数
| [virtual] |
小数点として使用する文字を提供します (virtual protected member function) |
| [virtual] |
千単位の区切り文字として使用する文字を提供します (virtual protected member function) |
| [virtual] |
各桁区切り記号のペア間の桁数を提供します。 (virtual protected member function) |
| [virtual] |
ブール値 true と false の名前として使用される文字列を提供します。 (virtual protected member function) |
[編集] 例
次の例は、true および false の文字列表現を変更します。
このコードを実行
#include <iostream> #include <locale> struct french_bool : std::numpunct<char> { string_type do_truename() const override { return "vrai"; } string_type do_falsename() const override { return "faux"; } }; int main() { std::cout << "default locale: " << std::boolalpha << true << ", " << false << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new french_bool)); std::cout << "locale with modified numpunct: " << std::boolalpha << true << ", " << false << '\n'; }
出力
default locale: true, false locale with modified numpunct: vrai, faux
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 338 | C++98 | sign トークンは、+ または - の後にオプションの空白を許可していました。 |
空白が削除されました。 |
[編集] 関連項目
| 指定されたロケールの numpunct ファセットを作成します。 (クラステンプレート) |