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

Popular posts from this blog

python - Why doesn't list have safe "get" method like dictionary? -

razor - Is this a bug in WebMatrix PageData? -

sql server - Stored procedure -