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 旗標,運算子略過前置空白字元。 它會讀取下列所有字元,直到下一個字元是泛空白字元或檔案結尾為止。
樣板函式多載 operator>> 是從資料流擷取的項目序列取代順序由 _Right_Istr。 擷取停駐點:
在檔案結尾。
在函式之後擷取 _Istr。width 項目,則為,如果該值為非零值。
在函式之後擷取 _Istr。max_size 項目。
- 在函式之後擷取項目 use_facet<ctype<CharType> >的 ch ( getloc)。 is( ctype<CharType>::space, 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
需求
標頭:<string>
命名空間: std