主题:菜鸟急求关于数据保存问题!!
将对话框中输入的数据保存为txt格式的文件,为什么文件里有很多的“?”问号,将文件中改动任意字符,再读取就是乱麻!!
void CMyDlg::OnOK()
{
UpdateData();
CFileDialog dlg(FALSE);
CString FilePathName;
char cFilter[]="All files(*.txt)\0*.*\0";
dlg.m_ofn.lpstrFilter=cFilter;
int iResult;
iResult=dlg.DoModal();
if(iResult==IDOK)
{
CString msg;
msg="File to open:";
msg+=dlg.GetFileName();
MessageBox(msg);
FilePathName=dlg.GetPathName();
}
CFile mFile;
mFile.Open(FilePathName, CFile::modeWrite|CFile::modeCreate);
mFile.Write(m_1,6);
mFile.Write("\t\n",2);
mFile.Write(m_2,6);
mFile.Write("\t\n",2);
mFile.Write(m_3,6);
mFile.Flush();
mFile.Close();
UpdateData(FALSE);
}
void CMyDlg::OnButton1()
{
UpdateData();
CString FilePathName;
CFileDialog dlg(TRUE);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
if(dlg.DoModal()==IDOK)
FilePathName=dlg.GetPathName();
CFile mFile;
mFile.Open(FilePathName, CFile::modeRead);
char buf[320];
//CArchive ar(&mFile);
//CString buf=ar.ReadString( );
mFile.Read(buf,8);
m_1=buf;
double m001=atof(m_1);
mFile.Read(buf,8);
m_2=buf;
double m002=atof(m_2);
mFile.Read(buf,8);
m_3=buf;
double m003=atof(m_3);
mFile.Close();
UpdateData(FALSE);
// TODO: Add your control notification handler code here
}
void CMyDlg::OnOK()
{
UpdateData();
CFileDialog dlg(FALSE);
CString FilePathName;
char cFilter[]="All files(*.txt)\0*.*\0";
dlg.m_ofn.lpstrFilter=cFilter;
int iResult;
iResult=dlg.DoModal();
if(iResult==IDOK)
{
CString msg;
msg="File to open:";
msg+=dlg.GetFileName();
MessageBox(msg);
FilePathName=dlg.GetPathName();
}
CFile mFile;
mFile.Open(FilePathName, CFile::modeWrite|CFile::modeCreate);
mFile.Write(m_1,6);
mFile.Write("\t\n",2);
mFile.Write(m_2,6);
mFile.Write("\t\n",2);
mFile.Write(m_3,6);
mFile.Flush();
mFile.Close();
UpdateData(FALSE);
}
void CMyDlg::OnButton1()
{
UpdateData();
CString FilePathName;
CFileDialog dlg(TRUE);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
if(dlg.DoModal()==IDOK)
FilePathName=dlg.GetPathName();
CFile mFile;
mFile.Open(FilePathName, CFile::modeRead);
char buf[320];
//CArchive ar(&mFile);
//CString buf=ar.ReadString( );
mFile.Read(buf,8);
m_1=buf;
double m001=atof(m_1);
mFile.Read(buf,8);
m_2=buf;
double m002=atof(m_2);
mFile.Read(buf,8);
m_3=buf;
double m003=atof(m_3);
mFile.Close();
UpdateData(FALSE);
// TODO: Add your control notification handler code here
}