【发布时间】:2018-06-06 09:21:09
【问题描述】:
我有一个自定义的std::streambuf。比如:
class mybuf : public std::streambuf {
...
virtual std::streambuf::int_type underflow() {
if(eof) {
return traits_type::eof();
}
...
}
...
std::istream stream(new mybuf(...));
通过在 underflow() 函数上返回 eof 来设置流的 eof 标志。
如何设置流的badbit 标志? overflow() 函数是否应该抛出异常?
【问题讨论】:
-
抛出异常,是的。见:stackoverflow.com/questions/12161728/…(或直接链接到
ios_base::iostate)