系统IO默认是不缓冲,但是不是说没缓冲区,而是会马上写到文件
标准IO,默认是全缓冲,只有
写满了这个缓冲区(系统MALLOC的,不是我们自己建的buffer)
使用了fllush函数
使用了fclose关闭文件
使用setbuf,setvbuf修改file*的属性
这3种情况才可以写进文件里面
标准IO,默认是全缓冲,只有
写满了这个缓冲区(系统MALLOC的,不是我们自己建的buffer)
使用了fllush函数
使用了fclose关闭文件
使用setbuf,setvbuf修改file*的属性
这3种情况才可以写进文件里面
/* setbuf example */
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char buffer[BUFSIZ];
FILE *pFile1, *pFile2;
pFile1=fopen ("myfile.txt","w");
pFile2=fopen ("myfile2.txt","a");
setbuf ( pFile1 , buffer );
fputs ("This is sent to a buffered stream",pFile1);
fputs ("This is sent to a buffered stream2",pFile1);
// fflush (pFile1);
setbuf ( pFile2 , NULL );
fputs ("This is sent to an unbuffered stream",pFile2);
// fclose (pFile1);
//fclose (pFile2);
system("pause");
return 0;
}