为什么带有\ n的printf()在Windows上仍然无法刷新?

问题描述 投票:0回答:3

我的Windows程序(使用MSYS2 MINGW64编译)以大块形式输出stdout数据。用printf()进行的\n调用无法正确刷新输出。

作为this question的变体,printf()在什么条件下不刷新?


作为示例,以下代码在MSYS2 MINGW64上的块中输出:

#include <stdio.h>

int main() {
        while(1) {
                printf("test\n");
                Sleep(1);
        }
        return 0;
}
c windows printf flush mingw-w64
3个回答
2
投票

在Windows上没有行缓冲,只有没有缓冲和完全缓冲


1
投票

printf()在什么条件下不刷新?


0
投票

作为其他答案的补充,您可以在printf中完成所有输出,只是不执行\n而在其后使用cout << endl。那应该刷新输出。

© www.soinside.com 2019 - 2024. All rights reserved.