新人自學MFC入門,老師要求讀取二進制檔案。
CFile Ffile;
CFileDialog fDlg(TRUE, NULL, NULL, 4 | 2,_TEXT("全部檔案(*.*)|*.*|(*.rbs_App*)|*.rbs_App*|文本檔案(*.txt,*.ini,*.log)|*.txt;*.ini;*.log||"));
if (fDlg.DoModal() == IDOK)
{
Path = fDlg.GetPathName();//獲取檔案路徑
CString str;
CStdioFile fFile;
CString temp = "solid";
Ffile.Open(Path, CFile::modeRead | CFile::typeBinary);
DWORD nFileLen = Ffile.GetLength();
float Other[84];
Ffile.Seek(0, CFile::begin);
Ffile.Read(Other, 84);
size_t Unit;
Unit = (nFileLen - 84) / 50;
for (size_t i = 0; i <= Unit; i++)
{
float xyz[12];
Ffile.Read(xyz, 48);
//verts.push_back(xyz[12]);
verts.push_back(xyz[0]);
verts.push_back(xyz[1]);
verts.push_back(xyz[2]);
for (size_t j = 1; j < 4; j++)
{
vnorms.push_back(xyz[j * 3]);
vnorms.push_back(xyz[j * 3 + 1]);
vnorms.push_back(xyz[j * 3 + 2]);
}
Ffile.Read(xyz, 2);
}
Ffile.Close();
}
用CFile::Read讀取二進制檔案的時候我把前84位元組先讀出去。
但是Ffile.Read(Other, 84);二進制STL檔案80-84位元組讀不胡來資料,讀后面坐標的時候讀的也不是正常資料。
還有在執行到結尾時報錯 vector subscript out of range是向量溢位,查過百度之后都對不上,想請教一下這是怎么回事?
uj5u.com熱心網友回復:
float Other[84]; // 即 84 個 浮點數 = ?位元組'Ffile.Read(Other, 84*sizeof(float));
uj5u.com熱心網友回復:
另外不要CStdioFile fFile; 用 CFile fFile轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/42135.html
標籤:基礎類
上一篇:mfc編程
下一篇:請教有關編譯出錯
