+ 1

need help in file handling c++

can't read data from file

8th Dec 2017, 2:04 PM
Farrukh Ijaz
Farrukh Ijaz - avatar
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.
8th Dec 2017, 4:25 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Thank you @Kinshuk! That's what I meant to talk about, but instead was just talking nonsense. I couldn't remember :D
9th Dec 2017, 2:34 AM
Zeke Williams
Zeke Williams - avatar
8th Dec 2017, 2:09 PM
Farrukh Ijaz
Farrukh Ijaz - avatar
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.
8th Dec 2017, 3:09 PM
Zeke Williams
Zeke Williams - avatar