Original Post
I''m having a problem reading in a binary file using fstream. I can open the file fine, I can read values individually just fine, but I run into problems when I try to read in a section of the file into a structure. Here''s what I got:
WORD a; DWORD b; m_fstrFile.read((unsigned char*)&a, 2); m_fstrFile.read((unsigned char*)&b, 4);This reads in perfectly fine, giving the correct values for a and b (a = 19,778 and b = 342,198). But this doesn''t work:
struct mystruct
{
WORD a;
DWORD b;
};
mystruct c;
m_fstrFile.read((unsigned char*)&c, sizeof(mystruct));
Here a is correctly given the value of 19,778 but b is given the value of 5.
Anyone have any clues why this isn''t working correctly?
- Houdini