unget是一種函式,作用是將最近讀取的字元回流。
基本介紹
- 外文名:unget
- 所屬類型:函式
basic_istream::unget,返回值,其他信息,示例,要求,
basic_istream::unget
將最近讀取的字元回流。
basic_istream<Elem, Tr>& unget( );
返回值
流(*this)。
其他信息
非格式化輸入函式 在流放回上一個元素,如有可能,就象通過調用 rdbuf - >sungetc。 如果 rdbuf 是null指針,或者,如果對 sungetc 的調用返回traits_type::eof,函式調用 setstate(badbit)。 在任一情況下,它將返回 *this。
示例
// basic_istream_unget.cpp
// updated by godspeed
#include <iostream>
using namespace std;
int main( ) {
char c[10], c2,c3;
cout << "Type 'abc': "; //列印提示符
c2 = cin.get( ); //取得c2
c3 = cin.get( ); //取得c3
cin.unget( ); //放回去上一個元素
cin.getline( c, 9 );
cout << c << endl;
}
//input:
//abcd
//output:
//bcd
要求
標頭: <istream>
命名空間: std

