请教underflow/overflow的问题

yuanwh 2003-03-25 05:16:52
一直不太明白streambuf的underflow和overflow的作用,所以写了以下代码测试一下,但发现underflow根本没有被调用到。请指教一下,谢谢!

class mystringbuf : public stringbuf {
protected:
virtual int_type underflow();
virtual int_type overflow(int_type c);
public:
mystringbuf(string &s, ios_base::openmode mode = ios_base::in | ios_base::out);
};

mystringbuf::mystringbuf(string &s, ios_base::openmode mode)
: stringbuf(s, mode) { }

mystringbuf::int_type mystringbuf::underflow()
{
cout << "underflow here";
return stringbuf::underflow();
}

mystringbuf::int_type mystringbuf::overflow(int_type c)
{
cout << "overflow here";
return stringbuf::overflow(c);
}

class imystringstream : public istream {
public:
explicit imystringstream(mystringbuf* sb);
};

imystringstream::imystringstream(mystringbuf* sb)
: istream(sb) { }

void test() {
mystringbuf buf("33 deg ddda dd");
imystreambuf s(&buf);
int i;
s >> i;
}
...全文
384 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lokioo 2003-04-01
  • 打赏
  • 举报
回复
stringbuf 就是缓冲区 ~~~~

你的程序调试没有结果阿
merlinran 2003-03-25
  • 打赏
  • 举报
回复
是不是一个输入时用,另一个输出时用。
瞎猜,不要介意。

上http://home.camelot.de/langer/Articles/去看一看,这两个作者可是io流方面的顶级专家哟。

24,853

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧