该注意的地方:
1、读文件操作中的file和path均在CXXApp类中定义,需要在CXXView中使用,我采用的方法是获取theApp对象,从而使用其中定义的file和path变量。在CXXView.cpp中定义:extern CDevicePackPlayerApp theApp;
2、CStdioFile读取文件的路径不能使用中文路径
=====================================================
以下是我的程序中部分代码
写文件操作:
CStdioFile stdiofile(csRscFile,CFile::modeCreate|CStdioFile::modeWrite|CFile::typeText);//scene目录下新建correct.txt来保存模型正确放置的位置
CString strx,stry,strz,strs; for (i=0;i<13;i++) { stdiofile.WriteString(model[i].name+_T("/n")); strx.Format("%d",model[i].x); //int转换CString类型 stry.Format("%d",model[i].y); strz.Format("%d",model[i].z); strs.Format("%d",model[i].isshow); stdiofile.WriteString(strx+_T(" ")); stdiofile.WriteString(stry+_T(" ")); stdiofile.WriteString(strz+_T(" ")); stdiofile.WriteString(strs+_T(" ")); stdiofile.WriteString(_T("/n")); }
读文件操作:
if(theApp.file.Open(theApp.path,CStdioFile::modeRead))
{
while (theApp.file.ReadString(ModelName)) { if (ModelName == "封箱机") { ModuleStatus = pView->m_converse.GetMeshGroupIsShown("封箱机"); //获取模型显示或隐藏的状态 switch(ModuleStatus) { case 0: //隐藏 MessageBox("0"); break; case 1: //显示 MessageBox("1"); break; case -1: //不存在 MessageBox("2"); break; default: break; } } else { // MessageBox(ModelName); } }
}