代码如下:
int nFileLen=mFile.SeekToEnd();//文件中已有其他内容
char c[3]="abc";
mFile.Write(c,3);
为什么总是从开头写起,原内容总是被覆盖

解决方案 »

  1.   

    先检查一下mFile.SeekToEnd();调用成功了没?
      

  2.   

    mFile.SeekToEnd()是否没有成功?mFile.SeekToEnd()之后是否做了别的操作,是否是多线程没有锁定
      

  3.   

    明白什么原因了,我打开文件时用的是:
    mFile.Open("my.txt",CFile::modeCreate |CFile::modeReadWrite); 
    我本来的意思是,如果文件不存在,则创建,但是这怎么不行阿,可以怎么办?
      

  4.   

    我把modeCreate去掉是过,但是不正确,文件不存在时不会创建文件,也就不能读写了
    分开两条语句可以实现,一条语句不知道行不
      

  5.   

    mFile.Open("my.txt",CFile::modeCreate |CFile::modeNoTruncate |CFile::modeReadWrite);CFile::modeNoTruncate   Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
      

  6.   

    你也可以先判断一下PathFileExists()文件存在否
      

  7.   

    可以先判断是否存在那个文件。
    CFile cf;
    if(!cf.Open("文件名",XXXXX);
    {
    //如果文件没有打开。该做什么做什么
    }
    else
    {
    cf.Close();
    }