名前空間
変種
操作

std::numpunct

From cppreference.com
< cpp‎ | locale
 
 
 
 
 
ヘッダー <locale> で定義
template< class CharT >
class numpunct;

std::numpunct ファセットは、数値の句読点の好みをカプセル化します。ストリーム I/O 操作は、数値入力の解析と数値出力のフォーマットのために、std::num_get および std::num_put を介して std::numpunct を使用します。

std::numpunct によってサポートされる数値は、以下に説明する形式を持ちます。ここで digitfmtflags 引数値によって指定される基数セットを表し、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'
cpp/locale/locale/facetstd-numpunct-inheritance.svg

継承図

目次

[編集] 特殊化

標準ライブラリは、以下の特殊化を提供することが保証されています(これらは あらゆるロケールオブジェクトによって実装される必要があります)。

ヘッダー <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 protected member function) [編集]
千単位の区切り文字として使用する文字を提供します
(virtual protected member function) [編集]
[virtual]
各桁区切り記号のペア間の桁数を提供します。
(virtual protected member function) [編集]
ブール値 truefalse の名前として使用される文字列を提供します。
(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 ファセットを作成します。
(クラステンプレート)
English 日本語 中文(简体) 中文(繁體)