windows的printf没有行缓冲,为什么?该怎么解决
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.