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

k3h5b8cx.collapse_all(zh-cn,VS.110).gifOutput

t
it worked
z

要求

标头: <streambuf>

命名空间: std

请参见

参考

basic_streambuf Class

iostream编程

(mfc)约定