c++ - Using fread/fwrite for STL string. Is it correct? -
i have structure, contain string. that:
struct chunk { int a; string b; int c; };
so, suppose, cannot write , read structure file using fread , fwrite functions. because string may reserve different memory capacity. such code works correctly.
chunk var;
fwrite(&var, sizeof(chunk), 1, file);
fread(&var, sizeof(chunk), 1, file);
is there problems in it?
you justified in doubting this. should stream pod types fwrite
, fread
, string
not pod
.
Comments
Post a Comment