CFile mFile;
mFile.Open("MyText.txt",CFile::modeRead);
CArchive ar(&mFile,CArchive::load);
CString MyStr="测试";
ar>>MyStr;
ar.Close();
mFile.Close();
数据是写入了,现在是想做到在文件最开头/尾部添加,而不是覆盖原来的文本。
请各位大哥帮帮。。
mFile.Open("MyText.txt",CFile::modeRead);
CArchive ar(&mFile,CArchive::load);
CString MyStr="测试";
ar>>MyStr;
ar.Close();
mFile.Close();
数据是写入了,现在是想做到在文件最开头/尾部添加,而不是覆盖原来的文本。
请各位大哥帮帮。。
如果是在开始加入,要先读出到缓冲区,和你要读入的连接起来再重新写入
throw( CFileException );Return ValueThe length of the file in bytes.ResSets the value of the file pointer to the logical end of the file. SeekToEnd() is equivalent to CFile::Seek( 0L, CFile::end ).Example//example for CFile::SeekToEnd
extern CFile cfile;
DWORD dwActual = cfile.SeekToEnd();
用SeekToEnd把文件指针移动到最后,再写入;2.在前面添加;
把当前文件所有内容读出来,把你想添加的内容和原来读出的内容组合,再写回去
注意文件的打开模式,要加上访问模式 CFile::modeNoTruncate ;2.最前面添加
就如楼上所言,要需要重新组织文件
都没用