I'm not a c++ expert but I've serialized things a couple of times in the past. Unfortunately this time I'm trying to serialize a class which contains an std::string
, which I understand is pretty much like serializing a pointer.
I can write out the class to a file and read it back in again. All int
fields are fine, but the std::string
field gives an "address out of bounds" error, presumably because it points to data which is no longer there.
Is there a standard workaround for this? I don't want to go back to char
arrays, but at least I know they work in this situation. I can provide code if necessary, but I'm hoping I've explained my problem well.
I'm serializing by casting the class to a char*
and writing it to a file with std::fstream
. Reading of course is just the reverse.