I have an object with several vector of other objects as members. I want to write this object to the fi开发者_开发百科le all at once(in binary mode), instead of writing each members. How can I do that? in this case i want to write object "A" from class AccList(all of my data saved in "A"!) this is my ClassDiagram: http://askus.ir/ClassDiagram1.png
You could use boost::serialization
you can use boost::serialization for do that
you must add one method at your object
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & this->foo & this->bar;
}
this method define what member has to be stored
after, for save your object you must do:
std::ofstream ofs("filename");
boost::archive::binary_oarchive oa(ofs);
oa << data;
for read the object, it's the same way,
std::ifstream ifs("filename");
boost::archive::binary_iarchive ia(ifs);
ia >> data;
tutorial
精彩评论