I have a C++ objects that looks like this
class myClass
{
vector<OtherClass*> otherClassVector;
AnotherClass* anotherClassObj;
// A few other primitive types and functions
}
What is the best way to store this to disk and read it back programmatically?
Will using fstream read/write in binary mode work? Or should I use boost serialization? And why?
I don’t require the stored file to be human readable.
Using
boost::serializationis simply, than write your own serializer. If OtherClass is concrete type (not base) – serialize by read/write is simple, for vector – just save size and than array (if your myClass has no non-POD types) and then store element on which points anotheClassObj pointer…