C++ streambuf - sbumpc
描述
它用于获取当前字符并前进到下一个位置并返回受控输入序列当前位置的字符,并将位置指示器前进到下一个字符。
声明
以下是 std::basic_streambuf::sbumpc 的声明。
int_type sbumpc();
参数
none
返回值
它返回调用前受控输入序列当前位置的字符,使用成员 traits_type::to_int_type 转换为 int_type 类型的值。
异常
Basic guarantee − 如果抛出异常,则流缓冲区处于有效状态。
数据竞争
它修改流缓冲区对象。
示例
在下面的例子中解释了 std::basic_streambuf::sbumpc。
#include <iostream>
#include <fstream>
int main () {
std::ifstream istr ("sample.txt");
if (istr) {
std::streambuf * pbuf = istr.rdbuf();
while ( pbuf->sgetc() != std::streambuf::traits_type::eof() ) {
char ch = pbuf->sbumpc();
std::cout << ch;
}
istr.close();
}
return 0;
}

