首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_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)

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

read

extracts blocks of characters (public member function)

readsome

extracts already available blocks of characters (public member function)

get

extracts characters (public member function)

getline

extracts 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)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com