原函数:
int fflush(FILE *stream)
函数说明: int fflush(FILE *stream)流刷新输出缓冲区。
参数:
- stream -- 是一个文件对象,它指定了一个缓冲的流指针。
返回值:
函数返回零值成功。如果出现错误,则返回EOF并设置错误指示灯(即feof)。
如何使用fflush() 函数:
#include <stdio.h>
int main() {
char buff[1024];
memset( buff, '', sizeof( buff ));
fprintf(stdout, "Going to set full buffering on \n");
setvbuf(stdout, buff, _IOFBF, 1024);
fprintf(stdout, "This is myfoal.com \n");
fprintf(stdout, "This output will go into buff \n");
fflush( stdout );
fprintf(stdout, "will come after sleeping 5 seconds \n");
sleep(5);
return 0;
}
编译和运行上面的程序,产生如下结果。
Going to set full buffering on
This is myfoal.com
This output will go into buff
will come after sleeping 5 seconds