Chinaunix首页 | 论坛 | 博客
  • 博客访问: 324691
  • 博文数量: 65
  • 博客积分: 1770
  • 博客等级: 上尉
  • 技术积分: 1125
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-13 14:31
文章分类

全部博文(65)

文章存档

2016年(1)

2014年(2)

2013年(5)

2012年(18)

2011年(39)

分类: LINUX

2012-02-22 17:17:11

fflush(stdin)刷新标准输入缓冲区,把输入缓冲区里的东西丢弃   
fflush(stdout)刷新标准输出缓冲区,把输出缓冲区里的东西打印到标准输出设备上。
fflush()默认是行缓冲,遇到\n就写内容清缓存
#include
#include
int main()
{
        printf("hello");
        fflush(stdout); //注释时,输入两个hello;
                  //不注释时,父进程缓存hello被清除,所以只输出一个
        fork();
        return 0;
}

  #include
  #include
  int main()
  {
          while(1)
          {
                  fprintf(stdout,"hello-out");
                  fflush(stdout);//注释时,不断输出hello-outhello-err;
                            //不注释时,内存中的hello-out被清除,所以结果只是不断输出hello-err
                  fprintf(stderr,"hello-err");
                  sleep(1);
          }
          return 0;
  }





















参考地址:
关于fflush-->
阅读(906) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~