I have a binary file with some layout I know. For example let format be like this:
You should better declare a structure (with 1-byte padding - how - depends on compiler). Write using that structure, and read using same structure. Put only POD in structure, and hence no std::string
etc. Use this structure only for file I/O, or other inter-process communication - use normal struct
or class
to hold it for further use in C++ program.