basic_streambuf::sputbackc
在流中char_type。
int_type sputbackc(
char_type _Ch
);
参数
- _Ch
字符。
返回值
返回字符或系统崩溃。
备注
如果放回位置可用,并 _Ch 与该位置的字符相等,成员函数递减输入缓冲区的指针下并返回 traits_type::to_int_type(_Ch)。 否则,它将返回 pbackfail(_Ch)。
示例
// basic_streambuf_sputbackc.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>
int main( )
{
using namespace std;
ifstream myfile("basic_streambuf_sputbackc.txt",
ios::in);
int i = myfile.rdbuf()->sbumpc();
cout << (char)i << endl;
int j = myfile.rdbuf()->sputbackc('z');
if (j == 'z')
{
cout << "it worked" << endl;
}
i = myfile.rdbuf()->sgetc();
cout << (char)i << endl;
}
输入:basic_streambuf_sputbackc.txt
testing
Output
t
it worked
z
要求
标头: <streambuf>
命名空间: std