다음을 통해 공유


basic_istream::getline

Gets a line from the input stream.

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

매개 변수

  • _Count
    The number of characters to read from strbuf.

  • _Delim
    The character that should terminate the read if it is encountered before _Count.

  • _Str
    A string in which to write.

반환 값

The stream (*this).

설명

The first of these unformatted input functions returns getline(_Str, _Count, widen('\n')).

The second function extracts up to _Count - 1 elements and stores them in the array beginning at _Str. It always stores the string termination character after any extracted elements it stores. In order of testing, extraction stops:

  • At end of file.

  • After the function extracts an element that compares equal to _Delim, in which case the element is neither put back nor appended to the controlled sequence.

  • After the function extracts _Count - 1 elements.

If the function extracts no elements or _Count - 1 elements, it calls setstate(failbit). In any case, it returns *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;
}
  

요구 사항

Header: <istream>

네임스페이스: std

참고 항목

참조

basic_istream 클래스

iostream 프로그래밍

iostreams 규칙