新人自学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);![图片说明](https://img-ask.csdn.net/upload/201906/04/1559613254_211205.png)二进制STL文件80-84字节读不胡来数据,读后面坐标的时候读的也不是正常数据。
还有在执行到结尾时报错 vector subscript out of range是向量溢出,查过百度之后都对不上,想请教一下这是怎么回事?