operator>> (<string>)
读取输入流的字符串的模板函数。
template<class CharType, class Traits, class Allocator>
basic_istream<CharType, Traits>& operator>>(
basic_istream<CharType, Traits>& _Istr,
basic_string<CharType, Traits, Allocator>& _Right
);
参数
_Istr
用于的内容提取序列_Right
输入流提取的字符串。
返回值
读取指定字符串的值从 _Istr 并返回到 _Right.
备注
除非将 skipws 标志设置中,运算符跳过前导空格。 它读取任何以下字符,直至下一个字符为空白或文件的末尾为止。
模板函数重载 运算符>> 将从当前提取的元素序列替换顺序由 _Right 控制 _Istr。 提取终止:
在文件尾。
在函数后提取 _Istr。width 元素,因此,如果该值不为零。
在函数后提取 _Istr。max_size 元素。
- 在函数提取元素 的 chuse_facet<ctype<CharType之后> >( getloc)。 isctype<CharType>(或空间,ch) 为 true,在这种情况下,字符放回情况下。
如果函数不提取元素,它调用 setstate(ios_base::failbit)。 在任何情况下,则调用 istr。width(0 *) 并返回this。
示例
// string_op_read_.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
string c0;
cout << "Input a string c0 ( try: Fibonacci numbers ): ";
cin >> c0;
cout << "The string entered is c0 = " << c0 << endl;
}
输入
Fibonacci numbers
示例输出
Input a string c0 ( try: Fibonacci numbers ): Fibonacci numbers
The string entered is c0 = Fibonacci
要求
标头:< 字符串>
命名空间: std