三种方式写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/archive/2012/07/19/2598713.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    三种方式写CString文件

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/55937

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午6:57
下一篇 2023年2月9日 上午6:57

相关推荐