如何把一个vc++6.0编辑框内的内容保存到Txt文档内?

来源:百度知道 编辑:UC知道 时间:2024/05/10 06:53:34
编辑框变量为edit型的,不要通过cstring型保存的。最好写的详细一点,把具体代码写上。以下这种是行不通的:它的编辑框内容固定不变,而我要不断改变编辑框内的内容(没有中文),要能够让CString strValue自动获取
CFile file; file.Open(“C:\\test.txt“,CFile::modeCreate|CFile::modeWrite); CString strValue(_T(“2143453“));//此处为编辑框的内容 file.Write(strValue,strValue.GetLength()); file.Close();

试试这样:

CFile file;
file.Open("C:\\test.txt",CFile::modeCreate|CFile::modeWrite);
CString strValue;
GetDlgItemText(你EditBox的ID,strValue);//此处为编辑框的内容
file.Write(strValue,strValue.GetLength());
file.Close();

头文件中添加
#include <fstream.h>
#include <string>

//假设m_1 对应Editbox
UpdateData(1)
ofstream nn("abc.txt");
nn<<m_1;