测试缓冲区多大时刷新

看了《C++编程对缓冲区的理解》,自己试了下,结果为大小4KB。

#include <fstream>

using namespace std;

int main()
{
	ofstream outfile("test.txt");
	for (int i = 0; i < 4096; i++)
		outfile << 'a';
	system("PAUSE");
	outfile << 'b';
	system("PAUSE");

	return 0; 
}

在第一次出现“请按任意键继续. . .”时打开“test.txt”文件,发现是空的,按回车键后再打开是“aaaa....aaaa”,继续按回车键,打开是“aaaa....aaaab”。

把4096改成4095后:

在第一次出现“请按任意键继续. . .”时打开“test.txt”文件,发现是空的,按回车键后再打开还是为空的,继续按回车键,打开是“aaaa....aaaab”。

 

posted @ 2012-02-06 23:11  SubmarineX  阅读(138)  评论(0编辑  收藏  举报