我有这样的代码:
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}输出为hello-err hello-err hello-err hello-err hello-err hello-err,间隔为1秒。我想知道为什么hello-out从不打印出来。
发布于 2012-07-04 00:02:27
您需要对stdout进行fflush,因为通常stdout是行缓冲的,并且您不会在程序中发出新的行字符。
fprintf(stdout,"hello-out");
fflush(stdout);默认情况下,stderr不是完全缓冲的,因此您不需要对其进行fflush。
https://stackoverflow.com/questions/11314825
复制相似问题