+ 1
need help in file handling c++
can't read data from file
4 Answers
+ 3
You may need to put this after your headers:
#pragma pack(1)
What this does is sets a byte padding of one. The byte padding determines how much memory your class is allowed to store.
Eg, if you have a class
class a
{
int a; char b;
};
And you print the sizeof(a), you get an 8. This is as since int takes 4 bytes, the char is forced to occupy 8 bytes, as the memory blocks are made of size 4 bytes each. Thus, 3 bytes are wasted. So, we use pack(1), which forces the memory blocks be only allocated 1 byte each, ensuring presevation of memory.
+ 2
Thank you @Kinshuk! That's what I meant to talk about, but instead was just talking nonsense. I couldn't remember :D
0
What is the error or problems that you are getting? Sometimes, the compiler will wrap a class or struct with extra bits. So instead of writing out 23 bits, it will automatically write in blocks of 2, or 24 for this hypothetical example. I can't remember exactly how to fix it, but just look up #pragma push on Google, as well as #pragma pop. It might help.