basic_istream::getline

從輸入資料流取得一行。

basic_istream<Elem, Tr>& getline(
    char_type *_Str, 
    streamsize _Count
);
basic_istream<Elem, Tr>& getline(
    char_type *_Str, 
    streamsize _Count, 
    char_type _Delim
);

參數

  • _Count
    要讀取的字元數。 strbuf

  • _Delim
    應該結束讀取的字元是在 _Count之前發生。

  • _Str
    的字串編寫的。

傳回值

資料流 (*this)。

備註

第一個未格式化的輸入函式傳回 getline(_Str, _Count, widen(「\n」))。

第二個函式會將陣列開頭捕捉 _Count - 1 項目並將其儲存在 _Str。它只儲存於所要儲存的字串結尾字元,在任何捕捉的項目之後。依照中的測試順序,擷取停駐點:

  • 在檔案結尾。

  • 在函式擷取等於 _Delim之後的項目,請在 中,在項目沒有放回也不會加在受控制序列的情況下。

  • 在函式之後擷取 _Count - 1 個元素。

如果函式未擷取項目或 _Count - 1 個元素,它會呼叫 setstate(failbit)。不論是哪種情況,則會傳回 *this

範例

// basic_istream_getline.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main( ) 
{
   char c[10];

   cin.getline( &c[0], 5, '2' );
   cout << c << endl;
}
  

需求

標題: <istream>

命名空間: std

請參閱

參考

basic_istream Class

iostream 程式設計

iostreams 慣例