三种方式写CString文件

  1. // use C to write into file   
  2. FILE        *pFile=fopen("1.txt","w");  
  3. CString     strTemp = "hello world!";  
  4. fwrite(strTemp,1,strTemp.GetLength(),pFile);  
  5. fflush(pFile);  
  6. fclose(pFile);  
  7.   
  8. // use C++ to write into file   
  9. ofstream    ofs("2.txt");  
  10. CString     str = "Use C++.Hello World !";  
  11. ofs.write(str,str.GetLength());  
  12. ofs.flush();  
  13. ofs.close();  
  14.   
  15. // use MFC to write into file   
  16. CString     str = "Use CFile,Hello World !";  
  17. CFile       file("3.txt",CFile::modeCreate | CFile::modeWrite);  
  18. file.Write(str,str.GetLength());  
  19. file.Flush();  
  20. file.Close();  
一切源于对计算机的热爱
原文地址:https://www.cnblogs.com/liuweilinlin/p/2598713.html