共用方式為


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 項目。

  • 在函式中擷取項目 的 chuse_facet<ctype<CharType> >之後 ( getloc)。 is( ctype<CharType>::spacech) 是 true,在這種情況下,字元放回情況下。

如果函式未擷取項目,它會呼叫 setstate(ios_base::failbit)。 不論是哪一種,它會呼叫 istrwidth(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

請參閱

參考

string::operator>>