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

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -