在序列化的Boost代码示例中 bus schedule 在其输出文件“demofile.txt”中,第一行是:
"22 serialization::archive 16 0 0 6 0 0 0 0 0 6 24 4"
这是什么? dll版本号?我们可以抑制这种情况并仅存储数据本身吗?
最佳答案
那不是 Dll 版本。这是存档 header 。
通过使用归档标志来抑制它:
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;
}
当然,记得在恢复时做同样的事情!
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;
}
另见
关于c++ - 如何抑制 boost serialization::archive 中的额外信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49640567/