c - sleep 和输出刷新

标签 c

我在网上某处看到了下面的片段。以下程序不打印“hello-out”。我感觉的原因是因为在它真正从缓冲区刷新到控制台之前,

  #include <stdio.h>
  #include <unistd.h>
  int main()
  {
          while(1)
          {
                  fprintf(stdout,"hello-out");
                  fprintf(stderr,"hello-err");
                  sleep(1);
          }
          return 0;
  }

我的理由对吗?如果不是,正确的原因是什么?

最佳答案

您应该将 \n 放在字符串的末尾以将其刷新,或使用 fflush 将其强制清除。

关于c - sleep 和输出刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7733236/

相关文章:

c - 这两种函数指针调用语法变体如何工作?

c - 使用 extern 关键字的链接出现 undefined reference 错误

c - 如何增加 unsigned char * 的值

c - C 中的 "Error: array subscript is not an integer"带指针

c - 这个程序为 p 和 c 都给出了输出 "abc",但是如何呢?

c - fltk 提示 Windows 上的 gcc

c# - 将 C 套接字客户端连接到 C# 套接字服务器

python - 将Python编译成机器码可行吗?

c - 拆分不同文件中的进程

c - 使用 mac osx 和 c 的硬件信息