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

operator>>(std::basic_istream)

运算符>>%28std::basic[医]iStream%29

template< class CharT, class Traits > basic_istream& operator>>( basic_istream& st, CharT& ch template< class Traits > basic_istream& operator>>( basic_istream& st, signed char& ch template< class Traits > basic_istream& operator>>( basic_istream& 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...

二次

#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'; }

二次

产出:

二次

c = n cstr = greet f = 1.23

二次

另见

operator>>extracts formatted data (public member function)

© cppreference.com

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

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