向一个文件中写数据,如果想让文件是不断增大的,应该怎么做?
也就是说我每次向文件中写入数据时,保证原来的数据不被覆盖.

解决方案 »

  1.   

    CFile myFile;
    int nCount = myFile.Getlength();
    myFile.Seek(nCount,CFile::begin);
      

  2.   

    CFile::Seek 
    virtual LONG Seek( LONG lOff, UINT nFrom );
    throw( CFileException );Return ValueIf the requested position is legal, Seek returns the new byte offset from the beginning of the file. Otherwise, the return value is undefined and a CFileException object is thrown.ParameterslOffNumber of bytes to move the pointer.nFromPointer movement mode.  Must be one of the following values: CFile::begin   Move the file pointer lOff bytes forward from the beginning of the file.
    CFile::current   Move the file pointer lOff bytes from the current position in the file.
    CFile::end   Move the file pointer lOff bytes from the end of the file. Note that lOff must be negative to seek into the existing file; positive values will seek past the end of the file. 
    ResRepositions the pointer in a previously opened file. The Seek function permits random access to a file’s contents by moving the pointer a specified amount, absolutely or relatively. No data is actually read during the seek. When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.Example//example for CFile::Seek
    extern CFile cfile;
    LONG lOffset = 1000, lActual;
    lActual = cfile.Seek( lOffset, CFile::begin );
      

  3.   

    如果用FILE指针和fopen...这组操作,打开时指定方式为"a",即追加(append)
    如果用CFile类,打开后调用
    file.Seek(0,CFile::end);
    如果是CreateFile,要用
    SetFilePointer()了
      

  4.   

    CFile fl_ErrLog(StrErrLog, CFile::modeReadWrite); 
    int nCount = fl_ErrLog.GetLength();
    fl_ErrLog.Seek(nCount, CFile::begin);CArchive ar_ErrLog(&fl_ErrLog, CArchive::store);
    m_ErrLog.Serialize(ar_ErrLog);
    ar_ErrLog.Close();fl_ErrLog.Write("\n",1);
    fl_ErrLog.Close();
    写完一行后.myFile.write("\n",1)
    可是在我的程序中不好用啊,写进的数据还是没有换行.