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

operator>>(std::basic_istream)

template< class CharT, class Traits > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>& st, CharT& ch ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, signed char& ch ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, unsigned char& ch );

(1)

?

template< class CharT, class Traits> basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>& st, CharT* s ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, signed char* s ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, unsigned char* s );

(2)

?

?

(3)

?

template< class CharT, class Traits, class T > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>&& st, T& value );

(since C++11) (until C++17)

template< class CharT, class Traits, class T > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>&& st, T&& value );

(since C++17)

执行字符输入操作。

1%29表现为FormattedInputFunction.在构造和检查哨兵对象之后,该对象可能跳过前导空格,提取字符并将其存储到ch如果没有字符可用,则设置failbit%28eofbit设置为FormattedInputFunction29%。

2%29表现为FormattedInputFunction.在构造和检查哨兵对象之后,该对象可能跳过前导空格,然后提取连续字符并将它们存储在字符数组的连续位置,该字符数组的第一个元素由s.如果符合下列条件之一,则停止提取:

  • ctype<CharT>小面%29被找到。未提取空白字符。
  • st.width() - 1字符提取
  • 文件的结尾发生在输入序列%28中,这也是eofbit%29

在这两种情况下,都会增加一个空字符值。CharT()存储在输出的末尾。如果没有提取字符,则设置failbit%28空字符仍被写入输出%29中的第一个位置。最后,呼叫st.width(0)取消…的影响std::setw如果有的话。3%29。

Calls the appropriate extraction operator, given an rvalue reference to an input stream object (equivalent to st >> value).

(since C++11)(until C++17)

Calls the appropriate extraction operator, given an rvalue reference to an input stream object (equivalent to st >> std::forward<T>(value)). This function does not participate in overload resolution unless the expression st >> std::forward<T>(value) is well-formed.

(since C++17)

注记

提取流中最后一个字符的单个字符没有设置。eofbit这与其他格式化的输入函数不同,例如用operator>>,但此行为与std::scanf带着"%c"格式说明符。

参数

st

-

input stream to extract the data from

ch

-

reference to a character to store the extracted character to

s

-

pointer to a character string to store the extracted characters to

返回值

st...

二次

代码语言:javascript
复制
#include <iostream>
#include <iomanip>
#include <sstream>
 
int main()
{
    std::string input = "n greetings";
    std::istringstream stream(input);
    char c;
    const int MAX = 6;
    char cstr[MAX];
 
    stream >> c >> std::setw(MAX) >> cstr;
    std::cout << "c = " << c << '\n'
              << "cstr = " << cstr << '\n';
 
    double f;
    std::istringstream("1.23") >> f; // rvalue stream extraction
    std::cout << "f = " << f << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
c = n
cstr = greet
f = 1.23

二次

另见

operator>>

extracts formatted data (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com