CFile mFile; 
  mFile.Open ("Play.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
  CArchive ar(&mFile,CArchive::store); 
  CString strTem=m_string;//m_string 为一个编辑框的变量
  ar<<strTem;
  ar.Close(); 
  mFile.Close(); 用上述代码就可以把编辑框的内容写道Play.txt中,可是如果我再写一次的话,就会把原来的数据覆盖,不知道有什么方法可以避免,让他写完一条然后再写下一条?

解决方案 »

  1.   

    你每次都CFile::modeCreate怎么可能不覆盖保存CFile,打开一次,全部数据写完以后,在关闭
      

  2.   

    除非是把Play.txt再读取一遍,不过这样效率太低,你不好Close的晚点?
      

  3.   

    CStdioFile mFile("Play.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
    mFile.WriteString(m_string);
    mFile.Close();这个行不行?
      

  4.   

    先判断文件存不存在,如果已经存在就用读写模式打开文件,SeekToEnd后再写数据
      

  5.   

    咬定位到文件末尾阿mFile.SeekToEnd()
      

  6.   

    CFile::modeCreate不要,
    SeekToEnd!
      

  7.   

    CStdioFile mFile("Play.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);file.SeekToEnd();///移到文件尾mFile.WriteString(m_string);mFile.Close();要判断文件写了几条你可能需要将文件读出来在进行判断
      

  8.   

    按照上面的方法,我先写了两个字符串,比方说一个“123”,一个“456”,因为我知道我写的是两个字符串,所以读的时候我赋两个变量ar<<strTem<<strTem1;但是假设我不知道呢,我怎么读,怎么判断?如何定义变量的个数?
      

  9.   

    用CStdioFile代替CFile类,然后用WriteString写,再用ReadString读。