目的是要实现每次调用下面代码就在文本文件open.txt中写入一行字符,然后换行,字符定义在theword里面,每次内容都不一样,但长度一样(90个字符),可是执行的时候,总是只保存着最后一次写入的一行,以前的都被覆盖了,请问高手怎么该代码啊,谢谢! CString filename="g:\\open.txt";
CFile file((LPCTSTR)            filename,CFile::modeCreate|CFile::modeReadWrite);
CString nextline;
nextline.Format("\n");
         CString strBuf=theword+nextline;
file.SeekToBegin();
file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
  file.Close();

解决方案 »

  1.   

    CString filename="g:\\open.txt";
    DWORD dwFlag=CFile::modeReadWrite;
    if(_access(filename,0)!=0)
    {
       dwFlag|=CFile::modeCreate;
    }
    CFile file((LPCTSTR)            filename,dwFlag);
    CString nextline;
    nextline.Format("\n");
             CString strBuf=theword+nextline;
    file.SeekToBegin();
    file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
      file.Close();
      

  2.   

    file.SeekToBegin();
    file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
    每次都从文劲头开始写入当然覆盖了上次写入的内容!
      

  3.   

    void LOG(char* string, ...)
    {
    FILE* debugFile = fopen(szFileName, "a"); if(debugFile == NULL)
    return; va_list argList;
    va_start(argList, string); fprintf(debugFile, "%02d:%02d:%02d  ", tNow.GetHour(), tNow.GetMinute(), tNow.GetSecond()); vfprintf(debugFile, string, argList);
    fprintf(debugFile, "\r\n"); fflush(debugFile);
    fclose(debugFile);
    }
      

  4.   

    file.SeekToEnd();
    file.Write(...);
      

  5.   


    不能用啊
    error C2065: '_access' : undeclared identifier