I currently try to read the header of a simple bitmap file. For that reason I open the file and read it into a buffer and set the 'structure-pointer' at it's address.
Afterwards I try to 'cout' the header values. For the first two characters (BM) everything went fine. But when it comes to the filelength I do not achieve to get the propper output.
Does any of you have a hint for me what I am doing wrong?
Below you can find my code with a description of the header.
The data in file "redsquare.bmp" starts with hex: "42 4D 86 AC 00 00 00 00 00 00 7A 00"
If I have overseen to provide additional necessary information please let me know. This is my first post into a forum.
I learned that eg. filesize referes to wrong address since fields in structure are aligned to full 4 byte addresses. For example a char(1) field is filled up with 3 additional 'unused' bytes. The next field in struct starts afterwards.
An alignment on byte level can be achieved by the compiler statement #pragma pack(1) . But this correction can have impact on performance.