fflush--stderr--stdout
来源:互联网 发布:update sql 编辑:程序博客网 时间:2024/05/22 03:34
一个小程序;
#include <stdio.h>#include <unistd.h> int main() { int i; for(i=0;i<3;i++) { fprintf(stdout,"hello-out"); fflush(stdout); fprintf(stderr,"hello-err"); sleep(1); } printf("\n"); return 0; }当屏蔽fflush(stdout);时,打印:hello-errhello-errhello-errhello-outhello-outhello-out
当不屏蔽时,打印:hello-outhello-errhello-outhello-errhello-outhello-err
为什么?
stderr -- 标准错误输出设备
stdout -- 标准输出设备 (printf("..")) 两者默认向屏幕输出。
但如果用转向标准输出到磁盘文件,则可看出两者区别。stdout输出到磁盘文件,stderr在屏幕。
函数名: fflush
功 能: 清楚读写缓冲区,需要立即把输出缓冲区的数据进行物理写入时
当有fflush(stdout)时:清空输出缓冲区,并把缓冲区内容输出,即输出hello-out当没有fflush(stdout)时,hello-out在缓冲区,直到hello-err输入完成,再输入缓冲区内容。
但是,此时如果修改成这样:fprintf(stdout,"hello-out\n");
输出也是依次hello-out hello-err
如果只修改fprintf(stderr,"hello-err\n");,依旧是先输出三个hello-err后接着hello-out。
因为遇见 \n ,会输出缓冲区内容
0 0
- fflush--stderr--stdout
- fflush(stdout)
- fflush(stdin) fflush(stdout)
- fflush(stdout); fflush(stdin);
- fflush(stdout); fflush(stdin);
- fflush(stdin) & fflush(stdout)
- fflush(stdin)和fflush(stdout)
- fflush(stdin)和fflush(stdout)
- fflush(stdin)和fflush(stdout)
- fflush(stdin) 和 fflush(stdout)
- fflush(stdin)和fflush(stdout)
- fflush(stdin)和fflush(stdout) .
- fflush(stdin)与fflush(stdout)
- fflush(stdin)和fflush(stdout)
- fflush(stdin)和fflush(stdout)
- fflush(stdin)与fflush(stdout)
- 重定向stdout & stderr
- stdin,stdout,stderr
- Block动画
- IOS的变量前加extern和static字段
- hdu 1097 A hard puzzle(快速幂取模)
- 美元指数与人民币汇率
- linux实用技巧:你该使用ctags查找源码了
- fflush--stderr--stdout
- 华为机试:元素按奇偶排序
- 使用getIdentifier()获取资源Id
- iOS extern使用教程
- C#调用C++ 平台调用P/Invoke 函数指针/回调函数【二】
- trie后缀树字符串索引
- 二叉搜索树
- ios开发——详解sqlite数据库,封装数据库操作
- 在一个长度为10的整形数组中,已经放置好了任意10个整数。要求用户任意输入 一个整数,判断该数字是否在数组中。如果在,删除数组中该元素,并把后面的 元素往前挪。(让空出的位置在最后)