Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19526
  • 博文数量: 8
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 51
  • 用 户 组: 普通用户
  • 注册时间: 2015-09-24 11:44
文章分类

全部博文(8)

文章存档

2016年(3)

2015年(5)

我的朋友

分类: C/C++

2015-10-21 10:18:13

将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();  
阅读(2207) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~