请问在MFC中如何把程序中的一个数组中的数据保存到txt文件中?

[复制链接]
查看11 | 回复1 | 2010-3-29 15:51:36 | 显示全部楼层 |阅读模式
最简单的方法是:include //包含头文件,这是负责文件输入输出流的ifstream cin("文件名.txt");//重新定位数据流,这样以后输入的数据将从文件里输入ofstream cout("文件名.txt") ;// 重新定位数据流,这样以后输出数据的时候将输出到文件里十分好用的。比如,int a=6;ifstream cin("myword,txt"); cout<<a<<endl;//输入到文件里
回复

使用道具 举报

千问 | 2010-3-29 15:51:36 | 显示全部楼层
void CArrToFileDlg::OnButton1() { int datas[] = {1,2,8,9}; CString strFileName = "f:\\1.txt"; CFile file ; file.Open(strFileName,CFile::modeCreate|CFile::modeReadWrite); CString str; for(int i = 0 ; i < sizeof(datas)/sizeof(datas[0]) ; i++ ) {CString strTmp ;strTmp.Format("%d ",datas);str += strTmp ; } file.Write((LPCTSTR)str,str.GetLength()); file.Close();}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行