自定义ostream无需冲洗?
目前,我使用自定义 stringbuf 派生对象创建一个 ostream,但它使用sync() 在屏幕上打印文本。有没有办法避免冲洗呢?我真的很想做 logStream << “测试”;没有 std::flush 或 endl。
Currently I create an ostream with a custom stringbuf derived object, but it uses sync() to print text on the screen. Is there a way to avoid having to flush it? I really want to do logStream << "Test"; without std::flush or endl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅我对此相关问题的回答:自定义流到 C++ 中的方法?< /a>
您真正需要更改的是添加刷新而不是函数调用以及您的流而不是字符串流。
编辑:刚刚看到这是你的问题。不过答案仍然有效。
See my answer to this related question: Custom stream to method in C++?
All you really need to change is to add the flush instead of the function call and your stream instead of the stringstream.
Edit: Just saw that was your question. The answer still works though.