相信很多人都在网上看到关于vc文件操作的摘要:
http://blog.chinaunix.net/u2/67530/showart_602878.html
我懒得copy过来了, 其中有一段是用CFile进行操作:
CFile myFile;
CString strTemp;
myFile.Open(path,CFile::modeRead|CFile::typeBinary) ;
CArchive ar(&myFile,CArchive::load);
ar>>strTemp;
ar.Close();
myFile.Close();
使用以上程序段运行,很多人都会得到一个错误,试图越过其尾端对一未命名文件进行读写。
将ar>>strTemp注释掉,则不再报错,问题就出在ar>>strTemp;上。
在网上搜索,没有一个很明确的说法,唯一一个解决问题的兄弟说是因为使用数组越界了。
将 ar>>strTemp更改为
while(ar.ReadString(strTemp)){ AfxMessageBox(strTemp); }
问题解决,可逐行读取文件。
至于产生该问题的原因?请自己思考。