basic_streambuf::sungetc
从流获取字符。
int_type sungetc( );
返回值
返回字符或系统崩溃。
备注
如果放回位置可用,成员函数递减输入缓冲区的指针下并返回 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_sungetctxt.
testing
Output
t
e
e
t
t
要求
标头: <streambuf>
命名空间: std