linux打印重定向丢失问题

这是由于缓冲区造成的,解决方法如下:

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     fflush(stdout);
 6     setvbuf(stdout, NULL, _IONBF, 0);
 7 
 8     printf("Hello World!
");
 9      while(1);
10 
11     return 0;
12 }

在打印前加上5,6行

原文地址:https://www.cnblogs.com/live-program/p/11699226.html