std::num_get
提供: cppreference.com
ヘッダ <locale> で定義
|
||
template< class CharT, |
||
クラス std::num_get
は数値の文字列表現を解析するためのルールをカプセル化します。 具体的には、型 bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double および void* がサポートされます。 標準の書式付き入力操作 (cin >> n; など) は数値のテキスト表現を解析するために入出力ストリームのロケールの std::num_get
ファセットを使用します。
目次 |
[編集] 型の要件
-InputIt は LegacyInputIterator の要件を満たさなければなりません。
|
[編集] 特殊化
2つのスタンドアロンな (ロケール非依存の) 完全特殊化および2つの部分特殊化が標準ライブラリによって提供されます。
ヘッダ
<locale> で定義 | |
std::num_get<char> | 数値のナロー文字列解析を作成します |
std::num_get<wchar_t> | 数値のワイド文字列解析を作成します |
std::num_get<char, InputIt> | カスタム入力イテレータを用いて数値のナロー文字列解析を作成します |
std::num_get<wchar_t, InputIt> | カスタム入力イテレータを用いて数値のワイド文字列解析を作成します |
さらに、 C++ のプログラム内で構築されたすべてのロケールオブジェクトは、これらの特殊化の独自の (ロケール固有の) バージョンを実装します。
[編集] メンバ型
メンバ型 | 定義 |
char_type
|
CharT
|
iter_type
|
InputIt
|
[編集] メンバ関数
新しい num_get ファセットを構築します (パブリックメンバ関数) | |
num_get ファセットを破棄します (プロテクテッドメンバ関数) | |
do_get を呼びます (パブリックメンバ関数) |
[編集] メンバオブジェクト
static std::locale::id id |
ロケールの id (パブリックメンバオブジェクト) |
[編集] プロテクテッドメンバ関数
[仮想] |
入力ストリームから数値を解析します (仮想プロテクテッドメンバ関数) |
[編集] 例
Run this code
#include <iostream> #include <locale> #include <string> #include <sstream> #include <iterator> int main() { std::string de_double = "1.234.567,89"; std::string us_double = "1,234,567.89"; // parse using streams std::istringstream de_in(de_double); de_in.imbue(std::locale("de_DE")); double f1; de_in >> f1; std::istringstream us_in(de_double); us_in.imbue(std::locale("en_US.UTF-8")); double f2; us_in >> f2; std::cout << "Parsing " << de_double << " as double gives " << std::fixed << f1 << " in de_DE locale and " << f2 << " in en_US\n"; // use the facet directly std::istringstream s3(us_double); s3.imbue(std::locale("en_US.UTF-8")); auto& f = std::use_facet<std::num_get<char>>(s3.getloc()); std::istreambuf_iterator<char> beg(s3), end; double f3; std::ios::iostate err; f.get(beg, end, s3, err, f3); std::cout << "parsing " << us_double << " as double using raw en_US facet gives " << f3 << '\n'; }
出力:
Parsing 1.234.567,89 as double gives 1234567.890000 in de_DE locale and 1.234000 in en_US parsing 1,234,567.89 as double using raw en_US facet gives 1234567.890000
[編集] 関連項目
数値の区切り文字の規則を定義します (クラステンプレート) | |
文字シーケンスとして出力するために数値をフォーマットします (クラステンプレート) | |
書式付きデータを抽出します ( std::basic_istream<CharT,Traits> のパブリックメンバ関数)
|