首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

windows的printf没有行缓冲,为什么?该怎么解决

2012-05-21 
windows的printf没有行缓冲,为什么?大家可以测试一下,C/C++ code#includestdio.hchar buf[512] int mai

windows的printf没有行缓冲,为什么?
大家可以测试一下,

C/C++ code
#include<stdio.h>  char buf[512]; int main(){    setvbuf(stdout, buf, _IOLBF, 512);  //行缓冲    printf("hello\n");   //windows下遇到\n并不刷新缓冲区,但是linux下可以    fflush(stdout);    while(1);            return 0;}

大家可以测试一下,设置为行缓冲后,在linux下输出时遇到换行可以立即输出,但是windows下不能,说明windows的printf没有行缓冲,为什么?


[解决办法]
http://msdn.microsoft.com/en-us/library/86cebhfs(v=vs.71).aspx
_IOLBF
For some systems, this provides line buffering. However, for Win32, the behavior is the same as _IOFBF - Full Buffering.

热点排行