Home > Software engineering >  CFile: : Read couldn't Read the file content
CFile: : Read couldn't Read the file content

Time:09-17

Newcomer self-study MFC entry, the teacher asked to read binary files,


CFile Ffile;
CFileDialog fDlg (TRUE, NULL, NULL, 4 | 2, _TEXT (" all files (*. *) | *. * | (*. Rbs_App *) | *. * | rbs_App text file (*.txt, *. Ini, *. The log) | *. TXT. *. Ini. *. The log | | "));
If (fDlg DoModal ()==IDOK)
{
Path=fDlg. GetPathName ();//the file path
Cstrings STR.
CStdioFile fFile;
Cstrings 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;
The Unit=(nFileLen - 84)/50;
For (size_t I=0; I & lt;=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 & lt; 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 Read binary file when I put the first 84 bytes Read out,
But Ffile. Read (Other, 84); ! Binary STL file [images] (https://img-ask.csdn.net/upload/201906/04/1559613254_211205.png), 80-84 data bytes read no nonsense, nor is read behind the coordinates of the normal data,
And in the execution to the end times wrong vector subscript out of the range is a vector overflows, not to check after baidu, want to ask what is this?

CodePudding user response:

Float Other [84];//that is 84 floating point number=? Bytes
'Ffile. Read (Other, 84 * sizeof (float).

CodePudding user response:

And don't CStdioFile fFile; With a CFile fFile
  • Related