std::num_get
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <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;)I / O流的语言环境中使用std::num_get方面来解析的文字表示的数字.Original:
Class
std::num_get encapsulates the rules for parsing string representations of values of type bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, and void*. The standard formatting input operators (such as cin >> n;) use the std::num_get facet of the I/O stream's locale to parse the text representations of the numbers.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 类型要求
-InputIt must meet the requirements of InputIterator.
|
[编辑] 专业化
两个专业,两个部分专业所提供的标准库和所有语言环境中创建的对象在C + +程序实现
Original:
Two specializations and two partial specializations are provided by the standard library and are implemented by all locale objects created in a C++ program:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
| Defined in header
<locale> | |
| std::num_get<char> | 创建窄字符串解析数字
Original: creates narrow string parsing of numbers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| std::num_get<wchar_t> | 创建广泛的数字字符串解析
Original: creates wide string parsing of numbers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| std::num_get<char, InputIt> | 创建的窄字符串解析的数字使用自定义输入迭代器
Original: creates narrow string parsing of numbers using custom input iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| std::num_get<wchar_t, InputIt> | 创建使用自定义输入迭代器的数字的的宽字符串解析的
Original: creates wide string parsing of numbers using custom input iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 会员类型
| 会员类型
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
char_type
|
CharT
|
iter_type
|
InputIt
|
[编辑] 成员函数
| 构造一个新num_get方面 Original: constructs a new num_get facet The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 解构一个num_get方面 Original: destructs a num_get facet The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (受保护的成员函数) | |
| 调用 do_get Original: invokes do_get The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
[编辑] 会员对象
| static std::locale::id id |
“ID”的语言环境 Original: id of the locale The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员对象) |
[编辑] 受保护的成员函数
| [虚拟的] </ SPAN></div></div>
|
从输入流中解析了一些 Original: parses a number from an input stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (虚拟保护成员函数) |
[编辑] 为例
#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'; }
Output:
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
[编辑] 另请参阅
| 定义数字标点规则 Original: defines numeric punctuation rules The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) | |
| 格式数字输出的字符序列的值 Original: formats numeric values for output as character sequence The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) | |
| 提取物格式的数据 Original: extracts formatted data The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数of std::basic_istream)
| |
