首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

如何把编辑框中的数据存入新建立的txt中

2012-02-02 
怎么把编辑框中的数据存入新建立的txt中能不能给个代码啊我很菜,刚接触不久。就是要把一组编辑框中的数据存

怎么把编辑框中的数据存入新建立的txt中
能不能给个代码啊
我很菜,刚接触不久。
就是要把一组编辑框中的数据存入新建立的txt中       生成如1   2.4568
                                                                                                                                    2   3.5456
                                                                                                                                    3   5.6566
                                                                                                                                      .     .
                                                                                                                                      .     .

[解决办法]
CFile::Open,Write,Close
[解决办法]
CString strFileName = " ";
strFileName.Format( "输出文件.txt ",strTextName);
ofstream outFile(strFileName,ios_base::out | ios_base::app);
if (!outFile.good())
{
cerr < < "Error while opening output file " < < endl;
return -1;
}

CString str = " ";
把读到的内容格式为想要的内容存放在str中
outFile < < str < < endl;


用CFile比较简单

CFile destFile;
CFileException ex;
CStringpath; //txt文件保存路径
char buf[1024];//缓冲区变量,大小根据实际情况

...

if (!destFile.Open(path,
CFile::modeWrite|
CFile::shareExclusive|
CFile::typeBinary|
CFile::modeCreate, &ex))
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
::AfxMessageBox(szError);
return;
}

destFile.Write(buf, sizeof(buf));

destFile.Close();
摘自以前的帖子

热点排行