다음을 통해 공유


basic_streambuf::sungetc

스트림에서 문자를 가져옵니다.

int_type sungetc( );

반환 값

문자 또는 오류를 반환합니다.

설명

Putback 위치를 사용할 수 있으면 멤버 함수 감소 입력된 버퍼 및 반환에 대 한 다음 포인터 traits_type::to_int_type(*gptr).그러나이 항상 현재 버퍼의 상태를 캡처할 수 있도록 마지막 문자 읽기 확인 하려면 불가능 합니다.이 true 인 경우 함수 반환 pbackfail.이 상황을 피하기 위해 다시 호출 하 여 문자를 추적 sputbackc(ch), 제공 되지 않은 스트림의 시작 부분에 호출 하지 않는 한 다시 두 개 이상의 문자를 배치 하지 않을.

예제

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

int main( ) 
{
   using namespace std;

   ifstream myfile( "basic_streambuf_sungetc.txt", ios::in );

   // Read and increment
   int i = myfile.rdbuf( )->sbumpc( );
   cout << ( char )i << endl;

   // Read and increment
   i = myfile.rdbuf( )->sbumpc( );
   cout << ( char )i << endl;

   // Decrement, read, and do not increment
   i = myfile.rdbuf( )->sungetc( );
   cout << ( char )i << endl;

   i = myfile.rdbuf( )->sungetc( ); 
   cout << ( char )i << endl;

   i = myfile.rdbuf( )->sbumpc( );
   cout << ( char )i << endl;
}

입력: basic_streambuf_sungetc.txt

testing

zz53e1ew.collapse_all(ko-kr,VS.110).gifOutput

t
e
e
t
t

요구 사항

헤더: <streambuf>

네임 스페이스: std

참고 항목

참조

basic_streambuf Class

iostream 프로그래밍

iostreams 규칙