I have a structure containing a string. Something like that:
struct Chunk { int a; string b; int c; };
So, I suppose that I cannot write and read this structure from a file using the fread and fwrite functions. Because the line can reserve different memory capacity. But such code works correctly.
Chunk var;
fwrite(&var, sizeof(Chunk), 1, file);
fread(&var, sizeof(Chunk), 1, file);
Are there any problems in it?
source share