std::basic_istream::operator>>
来自cppreference.com
< cpp | io | basic istream
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| basic_istream& operator>>( short& value ); basic_istream& operator>>( unsigned short& value ); |
(1) | |
| basic_istream& operator>>( int& value ); basic_istream& operator>>( unsigned int& value ); |
(2) | |
| basic_istream& operator>>( long& value ); basic_istream& operator>>( unsigned long& value ); |
(3) | |
| basic_istream& operator>>( long long& value ); basic_istream& operator>>( unsigned long long& value ); |
(4) | (C++11 起) |
| basic_istream& operator>>( float& value ); basic_istream& operator>>( double& value ); |
(5) | |
| basic_istream& operator>>( bool& value ); |
(6) | |
| basic_istream& operator>>( void*& value ); |
(7) | |
| basic_istream& operator>>( basic_istream& st, std::ios_base& (*func)(std::ios_base&) ); |
(8) | |
| basic_istream& operator>>( basic_istream& st, std::basic_streambuf<CharT,Traits>* sb ); |
(9) | |
提取物num_get::get()
5) 原文:
Extracts an integer value by calling num_get::get()
通过调用num_get::get()提取一个浮点值
6)
7) 原文:
Extracts a floating point value by calling num_get::get()
通过调用num_get::get()中提取一个通用的指针值
8) 原文:
Extracts a generic pointer value by calling num_get::get()
呼叫func(*this);,
9) func是一个I / O机械手.原文:
Calls func(*this);, where
func is an I/O manipulator.表现为一个
UnformattedInputFunction。在构造和检查岗哨对象的,从输入流中提取的所有数据,并将其存储到sb。提取停止,如果满足下列条件之一:原文:
Behaves as an
UnformattedInputFunction. After constructing and checking the sentry object, extracts all data from the input stream and stores it to sb. The extraction stops if one of the following conditions are met:- 文件结束发生在输入序列中;原文:end-of-file occurs on the input sequence;
- 插入输出序列中的失败(在这种情况下,要被插入的字符没有提取);原文:inserting in the output sequence fails (in which case the character to be inserted is not extracted);
- 异常发生时(在这种情况下,异常被捕获).原文:an exception occurs (in which case the exception is caught).
-
在这两种情况下,存储在成员变量访问后续调用
gcount()提取的字符的数目 原文:
In either case, stores the number of characters extracted in the member variable accessed by subsequent calls to
gcount() 目录 |
[编辑] 注释
版本的操作员(1-7)表现为“格式化的输入功能”。也就是说,他们构建一个
sentry在一开始就冲了tie()'D缓冲区,如果需要,检查错误,并提取物和丢弃所有领先的空白字符,除非ios_base :: skipws标志被清除的对象。尝试输入只有当sentry对象返回true.原文:
The (1-7) versions of the operator behave as formatted input functions. That is, they construct a
sentry object at the beginning that flushes the tie()'d buffers if needed, checks for errors, and extracts and discards all leading whitespace characters unless the ios_base::skipws flag was cleared. The input is attempted only if the sentry object returns true.第8版)不构造的岗哨对象。第9版)构建了一个哨兵对象
noskipws设置为true.原文:
The version 8) does not construct the sentry object. The version 9) constructs a sentry object with
noskipws set to true.如果解压缩失败(例如,如果一个字母一个数字输入预期),
value保持不变failbit设置(至 C++11)原文:
If extraction fails (e.g. if a letter was entered where a digit is expected),
value is left unmodified and failbit is set (至 C++11)如果提取失败,将零写入到
valuefailbit设置。如果值太大或太小,不适合在value的提取结果,std::numeric_limits<T>::max()或std::numeric_limits<T>::min()书面和failbit标志被设置。 (C++11 起)原文:
If extraction fails, zero is written to
value and failbit is set. If extraction results in the value too large or too small to fit in value, std::numeric_limits<T>::max() or std::numeric_limits<T>::min() is written and failbit flag is set. (C++11 起)[编辑] 参数
| value | - | 提取的值存储到一个整数或浮点值
原文: reference to an integer or floating-point value to store the extracted value to |
| func | - | 的指针I / O机械手的功能
|
| sb | - | 指针的streambuffer写的所有数据
原文: pointer to the streambuffer to write all the data to |
[编辑] 返回值
*this
[编辑] 示例
#include <iostream> #include <iomanip> #include <sstream> int main() { std::string input = "41 3.14 false hello world"; std::istringstream stream(input); int n; double f; bool b; stream >> n >> f >> std::boolalpha >> b; std::cout << "n = " << n << '\n' << "f = " << f << '\n' << "b = " << std::boolalpha << b << '\n'; // extract the rest using the streambuf overload stream >> std::cout.rdbuf(); std::cout << '\n'; }
输出:
n = 41 f = 3.14 b = false hello world
[编辑] 另请参阅
| 提取字符和字符数组 原文: extracts characters and character arrays (函数模板) | |
| 一个整数值,通过调用执行I / O流的字符串 (函数模板) | |
| 执行流的输入和输出的位集 原文: performs stream input and output of bitsets (函数) | |
| 序列化和反序列化一个复杂的数 原文: serializes and deserializes a complex number (函数模板) | |
| 执行流的输入和输出的伪随机数的发动机 原文: performs stream input and output on pseudo-random number engine (函数) | |
| 执行流输入和输出的伪随机数分布 原文: performs stream input and output on pseudo-random number distribution (函数) | |
| 提取的字符块 (公共成员函数) | |
| 提取已经可用块的字符 原文: extracts already available blocks of characters (公共成员函数) | |
| 提取字符 (公共成员函数) | |
| 提取字符,直到给定的字符被发现 原文: extracts characters until the given character is found (公共成员函数) | |