![]() |
#2
fxbszj2014-08-03 15:41
|

CFile SourceFile;//数据文件
CString SourceData;//定义一临时变量保存一条记录
CString strContents;
CFileException ex;
SourceFile.Open(regName,CFile::modeRead | CFile::shareDenyWrite, &ex);
CArchive ar(&SourceFile,CArchive::load);
while(NULL!=ar.ReadString(SourceData))//循环读取文件,直到文件结束
{
strContents+=SourceData+_T("\r\n");
if(SourceData=="")
continue;//跳过文件头部的提示信息
}
ar.Close();
SourceFile.Close();
//测试读取到的字符串
MessageBox(NULL,strContents,_T("Test"),MB_OK);
CString SourceData;//定义一临时变量保存一条记录
CString strContents;
CFileException ex;
SourceFile.Open(regName,CFile::modeRead | CFile::shareDenyWrite, &ex);
CArchive ar(&SourceFile,CArchive::load);
while(NULL!=ar.ReadString(SourceData))//循环读取文件,直到文件结束
{
strContents+=SourceData+_T("\r\n");
if(SourceData=="")
continue;//跳过文件头部的提示信息
}
ar.Close();
SourceFile.Close();
//测试读取到的字符串
MessageBox(NULL,strContents,_T("Test"),MB_OK);
只有本站会员才能查看附件,请 登录
我需要记取.reg文件,将里面的%installdir%替换成当前程序路径。在读取写入.reg文件的时候总会乱码,附件中是我拿来测试的两个注册表,一个QQ的一个酷狗音乐的,其中总一个会乱码。试过CFile/CStdioFile/ReadFile等各种方法,vs2012sp1,用的是unicode字符集。我乃新手,多多指教。麻烦大神给看下,谢谢