我想创建一个文件,然后将几个字符串累加的写到一个文件中,该怎么做?
谢谢大家

解决方案 »

  1.   

    FILE *fp;
    fp = fopen("c:\\test.txt","w");
    CString str = "123A" ;
    str += "456B";
    fwrite((char*)str.GetBuffer(0),1,str.GetLength(),fp);
    fclose(fp);
      

  2.   

    ofstream out("Test.txt");
    out<<"Hello"<<endl;
    out.close();
      

  3.   

    CString + CFileOpenWriteClose
      

  4.   

    CStdioFile file;
    if(file.Open("cwa.cfg",CFile::modeNoTruncate | CFile::modeWrite | CFile::typeText))
    {
    CString strbuf;
    file.SeekToBegin(); strbuf = str1 + str2 ...;
    file.WriteString(strbuf);
    file.WriteString("\r\n");
             file.Close();
    }
      

  5.   

    之际先把字符串相加,然后打开文件,写
    file.open();
    file.writestring();
    file.close();
      

  6.   

    ostream out("Test.txt",ios::app); //追加到文件末尾
    out<<str1<<endl;
    out<<str2<<endl;
    out<<str3<<endl;
    out<<str4<<endl;
    out<<str5<<endl;
    ......
    out.close();