title: Serializing a class which contains a std::string
body: <p>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 <code>std::string</code>, which I understand is pretty much like serializing a pointer.</p>
  <p>I can write out the class to a file and read it back in again. All <code>int</code> fields are fine, but the <code>std::string</code> field gives an &quot;address out of bounds&quot; error, presumably because it points to data which is no longer there.</p>
  <p>Is there a standard workaround for this? I don't want to go back to <code>char</code> 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.</p>
  <p>I'm serializing by casting the class to a <code>char*</code> and writing it to a file with <code>std::fstream</code>. Reading of course is just the reverse.</p>