共用方式為


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-tw,VS.110).gifOutput

t
it worked
z

需求

標題: <streambuf>

命名空間: std

請參閱

參考

basic_streambuf Class

iostream 程式設計

iostreams 慣例