I have an object with several vector of other objects as members. I want to write this object to the file 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 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.