basic_streambuf::sputbackc

在流中 char_type。

int_type sputbackc( 
   char_type _Ch 
);

参数

  • _Ch
    字符。

返回值

返回字符或失败。

备注

如果放回位置可用,_Ch 比较与在此位置存储的字符,成员函数递减输入缓冲区的指针并返回 traits_type::to_int_type(_Ch)。 否则,返回 (_Ch)。pbackfail

示例

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

Enter:basic_streambuf_sputbackc.txt

testing

Output

t
it worked
z

要求

页眉: <streambuf>

命名空间: std

请参见

参考

basic_streambuf 类

iostream 编程

iostreams 约定