CFileを使ったファイルの一発読み書き

読み

	CFile	f;
	CString writeData="";

	if ( f.Open("test.txt",CFile::modeRead)	==	TRUE)
	{
		unsigned int	flen = (unsigned int)f.GetLength();
		unsigned char *data = (unsigned char *)malloc(flen+1);
		if ( data	!= NULL )
		{
			f.Read(data,flen);
			data[flen]	=	0;
			writeData =	data; 
			free(data);
			f.Close();
		}
	}

書き

	CFile	f;
	CString writeData="abcdefg";
	if ( f.Open("test.txt",CFile::modeCreate | CFile::modeWrite)	==	TRUE)
	{
		f.Write(writeData.GetBuffer(),writeData.GetLength());
		f.Close();
	}

ネタ元

blog.goo.ne.jp