<span style="font-family: Arial, Helvetica, sans-serif;">char writeBuffer[500]; // 要写入的数据的缓存 </span>
char readBuffer[500]; // 存放读取数据的缓存
LONGLONG lOff = 0; // 文件指针的偏移量,也是读取到的数据的总字节数
// 构造CFile对象,同时以创建和读写的方式打开文件E:\1.txt
CFile file(_T("e:\\1.txt"), CFile::modeCreate | CFile::modeReadWrite);
// 将写入数据的缓存中每个字节都赋值为字符c
memset(writeBuffer, 'c', sizeof(writeBuffer));
// 将数据写入到文件中
<strong>file.Write(writeBuffer, sizeof(writeBuffer)); </strong>
while (true)
{
// 以文件开头为基准,移动文件指针到lOff的位置
file.Seek(lOff, CFile::begin);
// 读取100个字节的数据到存放读取数据的缓存的readBuffer + lOff位置处
int nRet = file.Read(readBuffer + lOff, 100);
// 根据实际读取的字节数,增加文件指针的移动量
lOff += nRet;
// 如果读取数据时返回值小于指定的100,说明已到文件尾,跳出循环
if (nRet < 100)
break;
}
// 关闭文件
file.Close();
通过不同的系统工具打开文件
<strong>::ShellExecuteA(NULL,TEXT("open"),strFilePath,NULL,NULL,SW_SHOWNORMAL);</strong>