如何把编辑框中的数据存入新建立的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;
CString path; //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();
摘自以前的帖子
能不能给个代码啊
我很菜,刚接触不久。
就是要把一组编辑框中的数据存入新建立的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;
CString path; //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();
摘自以前的帖子