如何在调试模式下冲洗FMT输出?
我正在尝试 fmt ,我确实从代码中获得了下面的
#include <fmt/color.h>
int main() {
fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
"Hello, {}!\n", "world");
fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
fmt::emphasis::underline, "Hello, {}!\n", "???");
fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
"Hello, {}!\n", "??");
}
输出。如果我以调试模式越过每行,则没有输出?
也许应该冲洗?
我尝试了 fflush(stdout);
失败。
以下似乎有所帮助。有了它,我在中间睡着了。但是,在每行踏入每行时,在调试期间仍然没有打印。
setbuf(stdout, NULL);
int main() {
setbuf(stdout, NULL);
fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
"Hello, {}!\n", "world");
qDebug() << "1";
QThread::msleep(2000);
qDebug() << "2";
fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
fmt::emphasis::underline, "Hello, {}!\n", "???");
QThread::msleep(2000);
fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
"Hello, {}!\n", "??");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
fmt :: print
,可以使用fmt ::格式
并将其发送到std :: Cout
并使用std ::齐平
:Instead of using
fmt::print
, you could usefmt::format
and send that tostd::cout
and usestd::flush
:您可以使用
stderr
立即打印内容。描述
FMT使用缓冲输出。它带有其自己的缓冲区类。
它输出到
stdout
,我不确定qdebug
,但是从名称中,它不使用stdout
。确保检查“ 在终端中运行”编译器资源管理器中的复选框。
无论如何:您可以通过将
std :: file*
作为第一个参数来更改fmt :: print
的输出流。Compiler Explorer
我不知道手动冲洗FMT打印缓冲区的任何方法。我正在调查。
我研究了它(2024-03-26编辑)
,所以……没有办法(我知道)将
stdout
与stderr
。同步。
然而,
(
paraphrasing kiwixz 在
You can use
stderr
to print the content immediately.Description
fmt uses buffered output. It comes with its own buffer class.
It outputs to
stdout
, I'm not sure aboutqDebug
but from the name it doesn't usestdout
.Make sure to check the "Run in terminal" check box in Compiler Explorer.
In any case: you can change the output stream used by
fmt::print
by passing astd::FILE*
as the first argument.Detailed example on compiler explorer
I'm not aware of any way to flush the fmt print buffer manually. I'm looking into it.
I looked into it (2024-03-26 edit)
So… There's no way (I know off) to sync
stdout
withstderr
.However,
Finally,
Paraphrasing kiwixz's answer on an issue about this on the fmt repo.