   fwrite an object to file, strange problem
  I've been using fwrite to dump some structures to a file for later retrieval ad so far it has worked great, but now I have found a problem.I am trying to dump an object called "scene_object_store" of type "StoreSceneObject" which contains (among other things) four std::string objects: name, path, materialName and materialPath. All of the variables are written correctly and can be retrieved, except for the third std::string, materialName.In the debugger, I can see that scene_object_store contains all of the correct values but the data I retrieve from the file just has junk in materialName.The materialPath string works as I would expect it to and it is created, set and used in all the same places that materialName is so nothing is different between them.Has any one else experienced this or have any clues as to what I can do to fix it?   
 Serialization;  Are you writing (char*)&scene_store_object? That doesn't work for non-POD types.MVC's std::string implementation does something like this:class std::basic_string {  buffer[16];  char * heap_buffer;};If the text is less than 16 characters, then it will be written correctly simply because it is allocated inside buffer. If it's longer, it's allocated on heap, so buffer contains garbage, and actual data is in heap_buffer.Non-POD types need to be serialized explicitly. Handle each member individually (.size() and .c_str()).   ;  Thanks for pointing that out Antheus, the string in question was longer than 16 characters. I'll take a look at SiCrane's link now.Quick question, what do you mean by "non-POD"?   ;Quote:Original post by tcsavageThanks for pointing that out Antheus, the string in question was longer than 16 characters. I'll take a look at SiCrane's link now.Quick question, what do you mean by "non-POD"?POD stands for Plain Old Data, and like many acronyms can be found on Google.[Edited by - rip-off on May 17, 2009 10:50:41 AM];  That link is a lot less funny if you screw up the search text.   ;Quote:Original post by SiCraneThat link is a lot less funny if you screw up the search text.Arg, just dropped a " character in the link [sad]The other text wass actually HTML from my signature I think.   ;  POD C++2? What's the 2 for?   ;Quote:Original post by SiCranePOD C++2? What's the 2 for?That was my typo (I have corrected it in the mean time). I must not have hit shift when typing the quote. That is where the " character is on keyboards here (think it may differ on American keyboard layouts). Cheers for not making a big deal out of it or anything [grin]   