CFile mFile; 
mFile.Open("MyText.txt",CFile::modeRead); 
CArchive ar(&mFile,CArchive::load); 
CString MyStr="测试"; 
ar>>MyStr; 
ar.Close(); 
mFile.Close(); 
数据是写入了,现在是想做到在文件最开头/尾部添加,而不是覆盖原来的文本。
请各位大哥帮帮。。

解决方案 »

  1.   

    在末尾添加先seektoend(); 把文件指针移到最后在写入
    如果是在开始加入,要先读出到缓冲区,和你要读入的连接起来再重新写入
      

  2.   

    DWORD SeekToEnd( );
    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();
      

  3.   

    1.在最后添加
    用SeekToEnd把文件指针移动到最后,再写入;2.在前面添加;
    把当前文件所有内容读出来,把你想添加的内容和原来读出的内容组合,再写回去
      

  4.   

    1.最后添加
    注意文件的打开模式,要加上访问模式 CFile::modeNoTruncate   ;2.最前面添加
    就如楼上所言,要需要重新组织文件
      

  5.   

    谢谢! CFile::modeNoTruncate 我就是差这一句 我用了SeekToEnd
    都没用