在线文档教程
C++
输入/输出 | Input/output

std::basic_istream::operator>>

性病:基本[医]iStream::Operator>>

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)(since C++11)
basic_istream& operator>>( float& value basic_istream& operator>>( double& value basic_istream& operator>>( long double& value (5)
basic_istream& operator>>( bool& value (6)
basic_istream& operator>>( void*& value (7)
basic_istream& operator>>( std::ios_base& (*func)(std::ios_base&) (8)
basic_istream& operator>>( std::basic_ios<CharT,Traits>& (*func)(std::basic_ios<CharT,Traits>&) (9)
basic_istream& operator>>( basic_istream& (*func)(basic_istream&) (10)
basic_istream& operator>>( std::basic_streambuf<CharT,Traits>* sb (11)

1-4%29表现为FormattedInputFunction.在构造和检查哨兵对象(可能跳过前导空格)之后,通过调用std::num_get::get()

5%29表现为FormattedInputFunction.在构造和检查哨兵对象(可能跳过前导空格)之后,通过调用std::num_get::get()

6%29表现为FormattedInputFunction.在构造和检查哨兵对象(可能跳过前导空格)之后,提取bool通过调用std::num_get::get()

7%29表现为FormattedInputFunction.在构造和检查哨兵对象(可能跳过前导空格)之后,通过调用std::num_get::get()

8-10%29次电话func(*this,在哪里func是I/O操作器。

11%29表现为UnformattedInputFunction.在构造和检查哨兵对象之后,从输入流中提取所有数据并将其存储到sb.如果符合下列条件之一,则停止提取:

  • 文件结束发生在输入序列上;

  • 在输出序列中插入失败%28,在这种情况下,要插入的字符不会提取%29;

  • 异常发生在%28,在这种情况下,异常将被捕获,并且只有在以下情况下才会重新引发failbit中启用exceptions()29%。

在任何一种情况下,都存储通过后续调用访问的成员变量中提取的字符数。gcount().如果sb是一个空指针,它没有插入字符。sb,电话setstate(failbit)%28std::ios_base::failure如果启用%29。

If extraction fails (e.g. if a letter was entered where a digit is expected), value is left unmodified and failbit is set.(until 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.(since C++11)

参数

value-reference to an integer or floating-point value to store the extracted value to
func-pointer to I/O manipulator function
sb-pointer to the streambuffer to write all the data to

返回值

1-9-9 11%29*this

10%29func(*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

二次

另见

operator>>(std::basic_istream)extracts characters and character arrays (function template)
operator<<operator>>performs stream input and output on strings (function template)
operator<<operator>>performs stream input and output of bitsets (function template)
operator<<operator>>serializes and deserializes a complex number (function template)
operator<<operator>>performs stream input and output on pseudo-random number engine (function template)
operator<<operator>>performs stream input and output on pseudo-random number distribution (function template)
readextracts blocks of characters (public member function)
readsomeextracts already available blocks of characters (public member function)
getextracts characters (public member function)
getlineextracts characters until the given character is found (public member function)
from_chars (C++17)converts a character sequence to an integer or floating-point value (function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]iStream/算子[医]gtgt