自定义ostream无需冲洗?

发布于 2024-10-07 07:19:08 字数 127 浏览 0 评论 0原文

目前,我使用自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音栖息无 2024-10-14 07:19:08

请参阅我对此相关问题的回答:自定义流到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文