basic_streambuf::sungetc
從資料流取得字元。
int_type sungetc( );
傳回值
傳回字元或失敗。
備註
如果放回位置可用,成員函式以輸入緩衝區中的下一個指標並傳回 traits_type::to_int_type(*gptr)。 不過,為了所讀取的最後一個字元都是不可能的,以便在目前緩衝區的狀態中擷取。 如果為 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;
}
輸入:basic_streambuf_sungetctxt.
testing
Output
t
e
e
t
t
需求
標題: <streambuf>
命名空間: std