basic_istream 클래스

클래스에 의해 Tr문자 특성이 결정되는 형식의 요소를 사용하여 스트림 버퍼에서 요소 및 인코딩된 개체의 Char_Tchar_type추출을 제어하는 개체를 traits_type설명합니다.

구문

template <class Char_T, class Tr = char_traits<Char_T>>
class basic_istream : virtual public basic_ios<Char_T, Tr>

설명

오버로드 operator>> 되는 대부분의 멤버 함수는 형식이 지정된 입력 함수입니다. 다음 패턴을 따릅니다.

iostate state = goodbit;
const sentry ok(*this);

if (ok)
{
    try
    {
        /*extract elements and convert
            accumulate flags in state.
            store a successful conversion*/
    }
    catch (...)
    {
        try
        {
            setstate(badbit);

        }
        catch (...)
        {
        }
        if ((exceptions()& badbit) != 0)
            throw;
    }
}
setstate(state);

return (*this);

다른 많은 멤버 함수는 형식이 지정되지 않은 입력 함수입니다. 다음 패턴을 따릅니다.

iostate state = goodbit;
count = 0;    // the value returned by gcount
const sentry ok(*this, true);

if (ok)
{
    try
    {
        /* extract elements and deliver
            count extracted elements in count
            accumulate flags in state */
    }
    catch (...)
    {
        try
        {
            setstate(badbit);

        }
        catch (...)
        {
        }
        if ((exceptions()& badbit) != 0)
            throw;
    }
}
setstate(state);

두 함수 그룹은 요소를 추출하는 동안 파일의 끝을 발견하면 호출 setstate(eofbit) 합니다. 자세한 내용은 setstate를 참조하세요.

클래스 basic_istream<Char_T, Tr> 저장소의 개체:

  • 클래스 basic_ios<Char_T, Tr>의 가상 공용 기본 개체입니다. 자세한 내용은 basic_ios를 참조하세요.

  • 형식이 지정되지 않은 마지막 입력 작업의 추출 횟수입니다(이전 코드에서 호출 count 됨).

예시

입력 스트림에 대한 basic_ifstream 자세한 내용은 클래스 의 예제를 참조하세요.

생성자

생성자 Description
basic_istream basic_istream 형식의 개체를 생성합니다.

멤버 함수

멤버 함수 설명
gcount 서식이 지정되지 않은 마지막 입력 동안 읽은 문자 수를 반환합니다.
get 입력 스트림에서 하나 이상의 문자를 읽습니다.
getline 입력 스트림에서 한 줄을 읽습니다.
ignore 현재 읽기 위치에서 많은 요소를 건너뜁니다.
peek 읽을 다음 문자를 반환합니다.
putback 지정된 문자를 스트림에 넣습니다.
read 스트림에서 지정된 개수의 문자를 읽고 배열에 저장합니다.
readsome 버퍼에서 읽기만 합니다.
seekg 스트림에서 읽기 위치를 이동합니다.
sentry 중첩된 클래스는 선언에서 형식이 지정된 입력 함수 및 형식이 지정되지 않은 입력 함수를 구성하는 개체를 설명합니다.
swap basic_istream 개체를 제공된 basic_istream 개체 매개 변수로 교환합니다.
sync 스트림의 연결된 입력 디바이스를 스트림의 버퍼와 동기화합니다.
tellg 스트림에서 현재 읽기 위치를 보고합니다.
unget 가장 최근에 읽은 문자를 다시 스트림에 넣습니다.

연산자

연산자 설명
operator>> 입력 스트림에 대해 함수를 호출하거나 입력 스트림에서 형식이 지정된 데이터를 읽습니다.
operator= 이 개체에 연산자의 오른쪽에 있는 basic_istream을 할당합니다. 복사본을 남겨 두지 않는 참조와 rvalue 관련된 이동 할당입니다.

요구 사항

헤더<istream>:

네임스페이스:std

basic_istream::basic_istream

basic_istream 형식의 개체를 생성합니다.

explicit basic_istream(
    basic_streambuf<Char_T, Tr>* strbuf,
    bool _Isstd = false);

basic_istream(basic_istream&& right);

매개 변수

strbuf
basic_streambuf 형식의 개체입니다.

_Isstd
true표준 스트림인 경우 그렇지 않으면 . false

right
복사할 basic_istream 개체입니다.

설명

첫 번째 생성자는 호출 init(strbuf)하여 기본 클래스를 초기화합니다. 또한 추출 개수에 0을 저장합니다. 자세한 내용은 init를 참조하세요. 이 추출 횟수에 대한 자세한 내용은 클래스 개요의 설명 섹션을 basic_istream 참조하세요 .

두 번째 생성자는 move(right)를 호출하여 기본 개체를 초기화합니다. 또한 추출 횟수에 저장하고 추출 횟수에 0을 저장 right.gcount() 합니다 right.

예시

입력 스트림에 대한 basic_ifstream::basic_ifstream 자세한 내용은 예제를 참조하세요.

basic_istream::gcount

서식이 지정되지 않은 마지막 입력 동안 읽은 문자 수를 반환합니다.

streamsize gcount() const;

Return Value

추출 개수입니다.

설명

서식 없는 문자를 읽는 데 사용합니다 basic_istream::get .

예시

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

int main( )
{
   cout << "Type the letter 'a': ";

   ws( cin );
   char c[10];

   cin.get( &c[0],9 );
   cout << c << endl;

   cout << cin.gcount( ) << endl;
}
a
Type the letter 'a': a
1

basic_istream::get

입력 스트림에서 하나 이상의 문자를 읽습니다.

int_type get();

basic_istream<Char_T, Tr>& get(Char_T& Ch);
basic_istream<Char_T, Tr>& get(Char_T* str, streamsize count);
basic_istream<Char_T, Tr>& get(Char_T* str, streamsize count, Char_T delimiter);

basic_istream<Char_T, Tr>& get(basic_streambuf<Char_T, Tr>& strbuf);
basic_istream<Char_T, Tr>& get(basic_streambuf<Char_T, Tr>& strbuf, Char_T delimiter);

매개 변수

count
strbuf에서 읽을 문자 수입니다.

delimiter
이전에 count발견된 경우 읽기를 종료해야 하는 문자입니다.

str
쓸 수 있는 문자열입니다.

Ch
가져올 문자입니다.

strbuf
쓸 수 있는 버퍼입니다.

Return Value

매개 변수가 없는 형식 get 은 정수 또는 파일 끝으로 읽은 요소를 반환합니다. 다시 기본 양식은 스트림(*this)을 반환합니다.

설명

첫 번째 형식이 지정되지 않은 입력 함수는 가능한 경우 반환하는 것처럼 요소를 추출합니다 rdbuf->sbumpc. 그 외의 경우 traits_type::eof를 반환합니다. 함수가 요소를 추출하지 않으면 .를 호출합니다 setstate(failbit). 자세한 내용은 setstate를 참조하세요.

두 번째 함수는 동일한 방식으로 요소를 meta 추출합니다int_type. 비교가 같traits_type::eof으면 meta 함수는 .를 호출합니다setstate(failbit). 그렇지 않으면 에 저장됩니다 traits_type::to_char_type(meta)Ch. 함수에서 *this을 반환합니다. 자세한 내용은 to_char_type를 참조하세요.

세 번째 함수 get(str, count, widen('\n'))는 .

네 번째 함수는 요소를 추출하여 count - 1 .에서 str시작하는 배열에 저장합니다. 함수는 항상 추출하여 저장한 요소 뒤에 char_type을 저장합니다. 테스트 순서에서 추출은 다음에서 중지됩니다.

  • 파일의 끝.

  • 함수가 같 delimiter음과 비교하는 요소를 추출한 후 . 이 경우 요소는 제어되는 시퀀스로 다시 배치됩니다.

  • 함수가 요소를 추출한 count - 1

함수가 요소를 추출하지 않는 경우 setstate(failbit). 어떤 경우든 *this을 반환합니다.

다섯 번째 함수는 .를 반환합니다 get(strbuf, widen('\n')).

여섯 번째 함수는 요소를 추출하고 에 삽입합니다 strbuf. 추출은 파일 끝 또는 추출되지 않은 동일한 delimiter요소와 비교되는 요소에서 중지됩니다. 또한 삽입이 실패하거나 예외를 throw하면(catch했지만 다시 throw되지 않음) 문제의 요소를 추출하지 않고 중단합니다. 함수가 요소를 추출하지 않는 경우 setstate(failbit). 어떤 경우든 함수는 .를 반환합니다 *this.

예시

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

int main( )
{
   char c[10];

   c[0] = cin.get( );
   cin.get( c[1] );
   cin.get( &c[2],3 );
   cin.get( &c[4], 4, '7' );

   cout << c << endl;
}
1111

basic_istream::getline

입력 스트림에서 한 줄을 가져옵니다.

basic_istream<Char_T, Tr>& getline(
    char_type* str,
    streamsize count);

basic_istream<Char_T, Tr>& getline(
    char_type* str,
    streamsize count,
    char_type delimiter);

매개 변수

count
strbuf에서 읽을 문자 수입니다.

delimiter
이전에 count발견된 경우 읽기를 종료해야 하는 문자입니다.

str
쓸 수 있는 문자열입니다.

Return Value

스트림(*this)입니다.

설명

이러한 형식이 지정되지 않은 입력 함수 중 첫 번째 함수가 반환 getline(str, count, widen('\n'))됩니다.

두 번째 함수는 요소를 추출하여 count - 1 .에서 str시작하는 배열에 저장합니다. 함수는 항상 추출하여 저장한 요소 뒤에 문자열 종결 문자를 저장합니다. 테스트 순서에서 추출은 다음에서 중지됩니다.

  • 파일의 끝.

  • 함수가 같 delimiter음과 비교하는 요소를 추출한 후 . 이 경우 요소는 다시 배치되지 않으며 제어되는 시퀀스에 추가되지 않습니다.

  • 함수가 요소를 추출한 count - 1

함수가 요소나 count - 1 요소를 추출하지 않으면 호출 setstate(failbit)됩니다. 어떤 경우든 *this을 반환합니다. 자세한 내용은 setstate를 참조하세요.

예시

// 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;
}
121

basic_istream::ignore

현재 읽기 위치에서 많은 요소를 건너뜁니다.

basic_istream<Char_T, Tr>& ignore(
    streamsize count = 1,
    int_type delimiter = traits_type::eof());

매개 변수

count
현재 읽기 위치에서 건너뛸 요소의 수입니다.

delimiter
개수 ignore 이전에 발생한 경우 모든 요소를 읽은 후 delimiter 반환하고 허용하는 요소입니다.

Return Value

스트림(*this)입니다.

설명

형식이 지정되지 않은 입력 함수는 최대 count개 요소를 추출하고 삭제합니다. 그러나 같numeric_limits<int>::max으면 count 임의로 큰 것으로 간주합니다. 추출은 파일의 끝이나 동일한 delimiter 요소(추출된 요소)와 비교되는 요소 Chtraits_type::to_int_type(Ch) 에서 일찍 중지됩니다. 함수에서 *this을 반환합니다. 자세한 내용은 to_int_type를 참조하세요.

예시

// basic_istream_ignore.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
   using namespace std;
   char chararray[10];
   cout << "Type 'abcdef': ";
   cin.ignore( 5, 'c' );
   cin >> chararray;
   cout << chararray;
}
Type 'abcdef': abcdef
def

basic\_istream::operator>>

입력 스트림에 대해 함수를 호출하거나 입력 스트림에서 형식이 지정된 데이터를 읽습니다.

basic_istream& operator>>(basic_istream& (* Pfn)(basic_istream&));
basic_istream& operator>>(ios_base& (* Pfn)(ios_base&));
basic_istream& operator>>(basic_ios<Char_T, Tr>& (* Pfn)(basic_ios<Char_T, Tr>&));
basic_istream& operator>>(basic_streambuf<Char_T, Tr>* strbuf);
basic_istream& operator>>(bool& val);
basic_istream& operator>>(short& val);
basic_istream& operator>>(unsigned short& val);
basic_istream& operator>>(int& val);
basic_istream& operator>>(unsigned int& val);
basic_istream& operator>>(long& val);
basic_istream& operator>>(unsigned long& val);
basic_istream& operator>>(long long& val);
basic_istream& operator>>(unsigned long long& val);
basic_istream& operator>>(void *& val);
basic_istream& operator>>(float& val);
basic_istream& operator>>(double& val);
basic_istream& operator>>(long double& val);

매개 변수

Pfn
함수 포인터입니다.

strbuf
stream_buf 형식의 개체입니다.

val
스트림에서 읽은 값입니다.

Return Value

스트림(*this)입니다.

설명

<istream> 헤더도 몇몇 전역 추출 연산자를 정의합니다. 자세한 내용은 operator>> (\<istream>)를 참조하세요.

첫 번째 멤버 함수는 폼 istr >> ws 의 식이 호출 ws(istr)된 다음 반환 *this되도록 합니다. 자세한 내용은 ws를 참조하세요.

두 번째 및 세 번째 함수는 다른 조작자(예: hex유사하게 동작)를 보장합니다. 다시 기본 함수는 형식이 지정된 입력 함수입니다.

함수:

basic_istream& operator>>(
    basic_streambuf<Char_T, Tr>* strbuf);

null 포인터가 아닌 경우 strbuf 요소를 추출하여 에 strbuf삽입합니다. 추출은 파일의 끝에서 중지됩니다. 또한 삽입이 실패하거나 예외를 throw하면(catch했지만 다시 throw되지 않음) 문제의 요소를 추출하지 않고 중단합니다. 함수가 요소를 추출하지 않는 경우 setstate(failbit). 어떤 경우든 함수는 .를 반환합니다 *this. 자세한 내용은 setstate를 참조하세요.

함수:

basic_istream& operator>>(bool& val);

를 호출 use_facet< num_get<Char_T, InIt>(getloc).get( InIt(rdbuf), Init(0), *this, getloc, val)하여 필드를 추출하고 부울 값으로 변환합니다. 여기서는 InIt .로 istreambuf_iterator<Char_T, Tr>정의됩니다. 함수에서 *this을 반환합니다.

자세한 내용은 use_facet, getloc, get, rdbufistreambuf_iterator을 참조하세요.

각 함수:

basic_istream& operator>>(short& val);
basic_istream& operator>>(unsigned short& val);
basic_istream& operator>>(int& val);
basic_istream& operator>>(unsigned int& val);
basic_istream& operator>>(long& val);
basic_istream& operator>>(unsigned long& val);
basic_istream& operator>>(long long& val);
basic_istream& operator>>(unsigned long long& val);
basic_istream& operator>>(void *& val);

를 호출 use_facet<num_get<Char_T, InIt>(getloc).get(InIt(rdbuf), Init(0), *this, getloc, val)하여 필드를 추출하고 숫자 값으로 변환합니다. InIt 여기서는 형식 또는 필요에 따라 istreambuf_iterator<Char_T, Tr>정의됩니다 vallongunsigned longvoid *.

변환된 값을 형식 val으로 나타낼 수 없으면 함수가 호출됩니다 setstate(failbit). 어떤 경우든 함수는 .를 반환합니다 *this. 자세한 내용은 setstate를 참조하세요.

각 함수:

basic_istream& operator>>(float& val);
basic_istream& operator>>(double& val);
basic_istream& operator>>(long double& val);

를 호출 use_facet<num_get<Char_T, InIt>(getloc).get(InIt(rdbuf), Init(0), *this, getloc, val)하여 필드를 추출하고 숫자 값으로 변환합니다. InIt 여기서는 형식 valdoublelong double 또는 필요에 따라 istreambuf_iterator<Char_T, Tr>정의됩니다.

변환된 값을 형식 val으로 나타낼 수 없으면 함수가 호출됩니다 setstate(failbit). 어떤 경우든 *this을 반환합니다.

예시

// istream_basic_istream_op_is.cpp
// compile with: /EHsc
#include <iostream>

using namespace std;

ios_base& hex2( ios_base& ib )
{
   ib.unsetf( ios_base::dec );
   ib.setf( ios_base::hex );
   return ib;
}

basic_istream<char, char_traits<char> >& somefunc(basic_istream<char, char_traits<char> > &i)
{
   if ( i == cin )
   {
      cerr << "i is cin" << endl;
   }
   return i;
}

int main( )
{
   int i = 0;
   cin >> somefunc;
   cin >> i;
   cout << i << endl;
   cin >> hex2;
   cin >> i;
   cout << i << endl;
}

basic_istream::operator=

이 개체에 연산자의 오른쪽에 있는 basic_istream을 할당합니다. 복사본을 남겨 두지 않는 참조와 rvalue 관련된 이동 할당입니다.

basic_istream& operator=(basic_istream&& right);

매개 변수

right
basic_ifstream 개체에 대한 rvalue 참조입니다.

Return Value

*this을(를) 반환합니다.

설명

멤버 연산자가 .를 호출합니다 swap(right).

basic_istream::peek

읽을 다음 문자를 반환합니다.

int_type peek();

Return Value

읽을 다음 문자입니다.

설명

형식이 지정되지 않은 입력 함수는 가능한 경우 반환하는 것처럼 요소를 추출합니다 rdbuf->sgetc. 그 외의 경우 traits_type::eof를 반환합니다. 자세한 내용은 sgetceof를 참조하세요.

예시

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

int main( )
{
   char c[10], c2;
   cout << "Type 'abcde': ";

   c2 = cin.peek( );
   cin.getline( &c[0], 9 );

   cout << c2 << " " << c << endl;
}
abcde
Type 'abcde': abcde
a abcde

basic_istream::putback

지정된 문자를 스트림에 넣습니다.

basic_istream<Char_T, Tr>& putback(
    char_type Ch);

매개 변수

Ch
스트림에 다시 배치할 문자입니다.

Return Value

스트림(*this)입니다.

설명

형식이 지정되지 않은 입력 함수가능한 경우 호출rdbuf->sputbackc하는 것처럼 다시 Ch넣습니다. null 포인터이거나 반환할 호출인 경우 rdbuf 함수는 .를 호출합니다setstate(badbit).sputbackctraits_type::eof 어떤 경우든 *this을 반환합니다.

자세한 내용은 다음을 참조하세요.rdbuf, sputbackc, eofsetstate.

예시

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

int main( )
{
   char c[10], c2, c3;

   c2 = cin.get( );
   c3 = cin.get( );
   cin.putback( c2 );
   cin.getline( &c[0], 9 );
   cout << c << endl;
}
qwq

basic_istream::read

스트림에서 지정된 개수의 문자를 읽고 배열에 저장합니다.

이 메서드는 전달된 값이 정확한지 확인하기 위해 호출자를 사용하므로 보안상 위험할 수 있습니다.

basic_istream<Char_T, Tr>& read(
    char_type* str,
    streamsize count);

매개 변수

str
문자를 읽을 배열입니다.

count
읽을 문자 수입니다.

Return Value

스트림( *this)입니다.

설명

형식이 지정되지 않은 입력 함수는 요소를 추출하여 count .에서 str시작하는 배열에 저장합니다. 파일의 끝부분에 추출이 일찍 중지되며, 이 경우 함수가 호출합니다 setstate(failbit). 어떤 경우든 *this을 반환합니다. 자세한 내용은 setstate를 참조하세요.

예시

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

int main()
{
    char c[10];
    int count = 5;

    cout << "Type 'abcde': ";

    // Note: cin::read is potentially unsafe, consider
    // using cin::_Read_s instead.
    cin.read(&c[0], count);
    c[count] = 0;

    cout << c << endl;
}
abcde
Type 'abcde': abcde
abcde

basic_istream::readsome

지정한 개수의 문자 값을 읽습니다.

이 메서드는 전달된 값이 정확한지 확인하기 위해 호출자를 사용하므로 보안상 위험할 수 있습니다.

streamsize readsome(
    char_type* str,
    streamsize count);

매개 변수

str
readsome이 읽은 문자를 저장하는 배열입니다.

count
읽을 문자 수입니다.

Return Value

실제로 읽은 문자 수입니다 gcount.

설명

형식이 지정되지 않은 입력 함수는 입력 스트림에서 최대 count개 요소를 추출하여 str 배열에 저장합니다.

이 함수는 입력을 기다리지 않습니다. 읽을 수 있는 데이터는 무엇이든 읽습니다.

예시

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

int main( )
{
   char c[10];
   int count = 5;

   cout << "Type 'abcdefgh': ";

   // cin.read blocks until user types input.
   // Note: cin::read is potentially unsafe, consider
   // using cin::_Read_s instead.
   cin.read(&c[0], 2);

   // Note: cin::readsome is potentially unsafe, consider
   // using cin::_Readsome_s instead.
   int n = cin.readsome(&c[0], count);  // C4996
   c[n] = 0;
   cout << n << " characters read" << endl;
   cout << c << endl;
}

basic_istream::seekg

스트림에서 읽기 위치를 이동합니다.

basic_istream<Char_T, Tr>& seekg(pos_type pos);

basic_istream<Char_T, Tr>& seekg(off_type off, ios_base::seekdir way);

매개 변수

pos
읽기 포인터를 이동할 절대 위치입니다.

off
way를 기준으로 읽기 포인터를 이동할 오프셋입니다.

way
열거형 중 ios_base::seekdir 하나입니다.

Return Value

스트림(*this)입니다.

설명

첫 번째 멤버 함수는 절대 검색을 수행하고 두 번째 멤버 함수는 상대 검색을 수행합니다.

참고 항목

표준 C++는 텍스트 파일에서 상대 검색을 지원하지 않으므로 두 번째 멤버 함수를 텍스트 파일과 함께 사용하지 마세요.

false이 경우 fail 첫 번째 멤버 함수는 일부 pos_type 임시 개체에 대해 호출newpos = rdbuf->pubseekpos(pos)합니다newpos. 이 경우 fail 두 번째 함수는 .를 호출합니다newpos = rdbuf->pubseekoff( off, way).false 두 경우 모두(위치 지정 작업이 실패하는 경우 (off_type)newpos == (off_type)(-1) ) 함수가 호출 istr.setstate(failbit)합니다. 두 함수 모두 *this를 반환합니다.

true경우 fail 멤버 함수는 아무 것도 수행하지 않습니다.

자세한 내용은 다음을 참조하세요.rdbuf, pubseekpos, pubseekoffsetstate.

예시

// basic_istream_seekg.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main ( )
{
   using namespace std;
   ifstream file;
   char c, c1;

   file.open( "basic_istream_seekg.txt" );
   file.seekg(2);   // seek to position 2
   file >> c;
   cout << c << endl;
}

basic_istream::sentry

중첩된 클래스는 선언에서 형식이 지정된 입력 함수 및 형식이 지정되지 않은 입력 함수를 구성하는 개체를 설명합니다.

class sentry {
   public:
   explicit sentry(
      basic_istream<Char_T, Tr>& _Istr,
      bool _Noskip = false);
   operator bool() const;
   };

설명

true경우 _Istr.good 생성자는 다음을 수행합니다.

  • null 포인터가 아닌 경우 _Istr.tie 호출 _Istr.tie->flush 합니다.

  • 0이 아닌 경우 _Istr.flags & skipws 효과적으로 호출 ws(_Istr) 합니다.

이러한 준비 _Istr.good 후에는 false생성자가 호출 _Istr.setstate(failbit)합니다. 어떤 경우든 생성자는 에 의해 반환된 _Istr.good 값을 저장합니다 status. 이 저장된 값을 전달하기 위한 operator bool 이후 호출입니다.

자세한 내용은 good, tie, flush, ws, flags, skipwssetstate을 참조하세요.

basic_istream::swap

basic_istream 개체의 내용을 교환합니다.

void swap(basic_istream& right);

매개 변수

right
basic_istream 개체에 대한 lvalue 참조입니다.

설명

멤버 함수는 .를 호출합니다 basic_ios::swap(right). 또한 추출 개수를 right에 대한 추출 개수로 교환합니다. 자세한 내용은 basic_ios::swap를 참조하세요.

basic_istream::sync

스트림의 연결된 입력 디바이스를 스트림의 버퍼와 동기화합니다.

int sync();

Return Value

null 포인터인 경우 rdbuf 함수는 -1을 반환합니다. 그렇지 않으면 호출 rdbuf->pubsync합니다. 해당 호출이 -1을 반환하면 함수가 -1을 호출 setstate(badbit) 하고 반환합니다. 아닌 경우 함수는 0을 반환합니다. 자세한 내용은 pubsyncsetstate를 참조하세요.

basic_istream::tellg

스트림에서 현재 읽기 위치를 보고합니다.

pos_type tellg();

Return Value

스트림 내의 현재 위치입니다.

설명

이 경우 fail 멤버 함수는 .를 반환합니다rdbuf->pubseekoff(0, cur, in).false 그 외의 경우 pos_type(-1)를 반환합니다. 자세한 내용은 rdbufpubseekoff를 참조하세요.

예시

// basic_istream_tellg.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main()
{
    using namespace std;
    ifstream file;
    char c;
    streamoff i;

    file.open("basic_istream_tellg.txt");
    i = file.tellg();
    file >> c;
    cout << c << " " << i << endl;

    i = file.tellg();
    file >> c;
    cout << c << " " << i << endl;
}

basic_istream::unget

가장 최근에 읽은 문자를 다시 스트림에 넣습니다.

basic_istream<Char_T, Tr>& unget();

Return Value

스트림(*this)입니다.

설명

형식이 지정되지 않은 입력 함수는 가능한 경우 If를 null 포인터로 호출하거나 반환traits_type::eof을 호출 rdbufrdbuf->sungetc 하는 sungetc 경우 함수가 호출하는 것처럼 스트림에서 이전 요소를 다시 넣습니다setstate(badbit). 어떤 경우든 *this을 반환합니다.

자세한 내용은 sungetc, eofsetstate를 참조하세요. 그리고 실패할 수 있는 방법에 unget 대한 자세한 내용은 다음을 참조하세요 basic_streambuf::sungetc.

예시

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

int main( )
{
   char c[10], c2;

   cout << "Type 'abc': ";
   c2 = cin.get( );
   cin.unget( );
   cin.getline( &c[0], 9 );
   cout << c << endl;
}
abc
Type 'abc': abc
abc

참고 항목

C++ 표준 라이브러리의 스레드 보안
iostream 프로그래밍
iostreams 규칙