我把存有密码的dat文件放在"\FlashDisk\Program Files\Etonepay\manager_pw.dat"这个路径下,是原密码,想要读取里面的数据与界面上输入的原密码数据做比较,可是读取的一直不对。现在里面存的数据是12,我单步运行读取的不对,不知道是哪的问题。
void SysAdmin::OnOK()
{
UpdateData();
CFile SourceFile;//数据文件
CString SourceData;//定义一临时变量保存一条记录
CString appendstr;
CString strtmp;
CString tmp;
CFileException ex;
CString SourceData1;
SourceFile.Open(_T("\\FlashDisk\\Program\\Files\\Etonepay\\manager_pw.dat") ,CFile::modeRead | CFile::shareDenyWrite, &ex);
CArchive ar(&SourceFile,CArchive::load);
while(NULL!=ar.ReadString(SourceData))//循环读取文件,直到文件结束
{
strtmp.Format(_T("%s"),m_oldpw_text);
if(SourceData==strtmp)
{
tmp.Format(_T("%s"),appendstr);
strtmp.Format(_T("%s"),m_newpw_text);
//appendstr.Format(_T("%s%s\n"),tmp,strtmp);
AfxMessageBox(_T("修改成功!"));
}