다음을 통해 공유


basic_streambuf::sungetc

Gets a character from the stream.

int_type sungetc( );

반환 값

Returns either the character or failure.

설명

If a putback position is available, the member function decrements the next pointer for the input buffer and returns traits_type::to_int_type(*gptr). However, it is not always possible to determine the last character read so that it can be captured in the state of the current buffer. If this is true, then the function returns pbackfail. To avoid this situation, keep track of the character to put back and call sputbackc(ch), which will not fail provided you don't call it at the beginning of the stream and you don't try to put back more than one character.

예제

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

Input: basic_streambuf_sungetc.txt

testing

Output

t
e
e
t
t

요구 사항

Header: <streambuf>

네임스페이스: std

참고 항목

참조

basic_streambuf 클래스

iostream 프로그래밍

iostreams 규칙