先謝謝各位來看
關於open和save..=.=小弟有幾個問題
首先, 我把open和save分開兩個button
1. 在open button里, 我己經讀取了txt, 那怎么跳到txt檔內容的最後去writestring呢?2. 在save button里, 我要怎么才能把我要的東西, 在按下button後-->開啟瀏覽視窗-->用戶選位置-->選txt檔(如指定txt檔. 可以自己打名新建)儲存到該地方呢?3. 有方法可以判斷以下情況嗎. save和save as      save是指儲存到本身的txt檔中.  save as是指用戶指定新位置先謝謝各位幫忙><

解决方案 »

  1.   


         1. 在open button里, 我己經讀取了txt, 那怎么跳到txt檔內容的最後去writestring呢?  获取txt文件长度,将文件指针移到该位置,然后开始writestring就可以了。
      

  2.   

    CFileDialog dlg(TRUE);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
      

  3.   

    CFileDialog false
    CFileDialog cfg(FALSE,(LPCTSTR)   "*.txt|*.txt||",NULL,OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,  (LPCTSTR)     "*.txt|*.txt||",this,0);
    cfg.DoModal();
    --------------------------------
    是這樣嗎。  但哪里是我指定要儲存的資料
      

  4.   


    CFileDialog)   
        
      CFileDialog   dlg(TRUE,   
      _T("*.txt"),   
      NULL,   
      OFN_HIDEREADONLY   |   OFN_OVERWRITEPROMPT   |   OFN_ALLOWMULTISELECT,   
      _T("file   (*.txt)|*.txt||"),   
      this);   
        
      int   nOkCancel   =   dlg.DoModal();   
      if(nOkCancel   ==   IDOK)   
      {   
      //   append   file   to   list   
      POSITION   pos   =   dlg.GetStartPosition();   
                      while   (pos   !=   NULL)   
                      {   
                              CString   strFilePath=dlg.GetNextPathName(pos);   
      //   find   file   path   name   yes   or   no   in   the   list   
      if(m_ctlChoiseFileLt.FindString(-1,strFilePath)==LB_ERR)   
      {   
      //   no   find   string   then   append   to   list   
      m_ctlChoiseFileLt.AddString(strFilePath);   
      }   
                    }   
      }
      

  5.   


    抱歉啊.. 這兩句看不太明白><這是用來判斷之前有沒開啟過txt檔的嗎??
      

  6.   

    这是 oyljerry 写的代码,
    m_ctlChoiseFileLt 看名称和功能,
    应该是个 CListBox,用来显示“打开文件”对话框中选定的文件(已排除重复项)。
      

  7.   

    Moves the file pointer to a specified location. 
    int fseek( 
       FILE *stream,
       long offset,
       int origin 
    );
    int _fseeki64( 
       FILE *stream,
       __int64 offset,
       int origin 
    );
     Parameters
    stream
    Pointer to FILE structure.offset
    Number of bytes from origin.origin
    Initial position.Return Value
    If successful, fseek and _fseeki64 returns 0. Otherwise, it returns a nonzero value. On devices incapable of seeking, the return value is undefined. If stream is a null pointer, or if origin is not one of allowed values described below, fseek and _fseeki64 invoke the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, these functions set errno to EINVAL and return -1.Res
    The fseek and _fseeki64 functions moves the file pointer (if any) associated with stream to a new location that is offset bytes from origin. The next operation on the stream takes place at the new location. On a stream open for update, the next operation can be either a read or a write. The argument origin must be one of the following constants, defined in STDIO.H: SEEK_CUR
    Current position of file pointer.SEEK_END
    End of file.SEEK_SET
    Beginning of file.You can use fseek and _fseeki64 to reposition the pointer anywhere in a file. The pointer can also be positioned beyond the end of the file. fseek and _fseeki64clears the end-of-file indicator and negates the effect of any prior ungetc calls against stream.When a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. If no I/O operation has yet occurred on a file opened for appending, the file position is the start of the file. For streams opened in text mode, fseek and _fseeki64have limited use, because carriage return–linefeed translations can cause fseek and _fseeki64to produce unexpected results. The only fseek and _fseeki64operations guaranteed to work on streams opened in text mode are: Seeking with an offset of 0 relative to any of the origin values.Seeking from the beginning of the file with an offset value returned from a call to ftell when using fseekor _ftelli64when using_fseeki64.Also in text mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing, fopen and all related routines check for a CTRL+Z at the end of the file and remove it if possible. This is done because using the combination of fseek and ftellor_fseeki64 and _ftelli64, to move within a file that ends with a CTRL+Z may cause fseek or _fseeki64 to behave improperly near the end of the file. When the CRT opens a file that begins with a Byte Order Mark (BOM), the file pointer is positioned after the BOM (that is, at the start of the file's actual content). If you have to fseek to the beginning of the file, use ftell to get the initial position and fseek to it rather than to position 0.This function locks out other threads during execution and is therefore thread-safe. For a non-locking version, see _fseek_nolock, _fseeki64_nolock.
      

  8.   

    如果是CFile对象,可以使用Seek()、SeekToBegin()、SeekToEnd()方法设置文件指针。
    Repositions the pointer in a previously opened file. 
    virtual ULONGLONG Seek(
       LONGLONG lOff,
       UINT nFrom 
    );
     Parameters
    lOff
    Number of bytes to move the pointer.nFrom
    Pointer 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.Return Value
    If 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. Res
    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. If the requested position is larger than the size of the file, the file length will be extended to that position, and no exception will be thrown.When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.