问题
In the example of Boost code of serialization bus schedule in its output file "demofile.txt" the first line is:
"22 serialization::archive 16 0 0 6 0 0 0 0 0 6 24 4"
what is this? Dll version number? Can we suppress this and store only the data itsself?
回答1:
That's not a Dll version. It's the archive header.
Suppress it by using archive flags it:
void save_schedule(const bus_schedule &s, const char * filename){
// make an archive
std::ofstream ofs(filename);
boost::archive::text_oarchive oa(ofs, boost::archive::archive_flags::no_header);
oa << s;
}
And remember to do the same on restoring, of course!
void restore_schedule(bus_schedule &s, const char * filename) {
// open the archive
std::ifstream ifs(filename);
boost::archive::text_iarchive ia(ifs, boost::archive::archive_flags::no_header);
// restore the schedule from the archive
ia >> s;
}
See also
- Boost binary archives - reducing size
- Why does an non-intrusive serialization add a 5 byte zero prefix?
- Boost C++ Serialization overhead
来源:https://stackoverflow.com/questions/49640567/how-to-suppress-the-extra-information-in-boost-serializationarchive