从流获取字符。
int_type sungetc( );
返回值
返回字符或失败。
备注
如果放回位置可用,成员函数递减输入缓冲区的指针并返回 traits_type::to_int_typegptr(*)。 但是,位置读取的最后一字符始终是不可能的,以便在当前捕获状态的缓冲区。 如果为 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;
}
Enter:basic_streambuf_sungetc.txt
testing
Output
t
e
e
t
t
要求
页眉: <streambuf>
命名空间: std