我想多次往一个文件里存储string 应该怎么办?
我尝试一下方法:
        CStdioFile fstr;
CFileException e;

CString pFileName="C:\\test.wrl";

if(!fstr.Open(pFileName,CFile::modeCreate|CFile::modeWrite,&e))
{
acutPrintf(_T("\nCreate export faile!"));
return;
}
fstr.SeekToEnd();
fstr.WriteString(pStr);

fstr.Flush();这是在一个循环里面,pStr 是一个CString 对象 每次循环pStr的值不同,可是我存储的是最后一次的。我想都存储怎么
办啊?谢谢帮忙!!

解决方案 »

  1.   

    2次以后写入的时候把这个创建标志去掉——CFile::modeCreate
      

  2.   

    我这有个函数,也许可以帮到你,参考一下吧void WriteCStringArryToFile(CStringArray &strAry,LPCTSTR lpszFileName)
    {
    CStdioFile myfile;
    myfile.Open(lpszFileName,CFile::modeCreate|CFile::modeWrite);

    int size=strAry.GetSize();
    for(int i=0;i<size;i++)
    {
    CString str;
    str.Format("%s\n",strAry[i]);
    myfile.WriteString(str);
    }
    myfile.Close();
    }
      

  3.   

    把if(!fstr.Open(pFileName,CFile::modeCreate ¦CFile::modeWrite,&e)) 

    acutPrintf(_T("\nCreate   export   faile!")); 
    return; 

    fstr.SeekToEnd(); 
    拿到循环外面去呀,CFile::modeCreate会重建文件,如果以前文件存在它的内容会被清掉的
      

  4.   

    Thanks everyone !! I know now. Best wishes for you!