【发布时间】:2018-04-03 23:36:12
【问题描述】:
在序列化的Boost代码示例中 bus schedule 在其输出文件“demofile.txt”中,第一行是:
"22 serialization::archive 16 0 0 6 0 0 0 0 0 6 24 4"
这是什么? dll版本号?我们可以抑制这一点并仅存储数据本身吗?
【问题讨论】:
标签: c++ serialization boost
在序列化的Boost代码示例中 bus schedule 在其输出文件“demofile.txt”中,第一行是:
"22 serialization::archive 16 0 0 6 0 0 0 0 0 6 24 4"
这是什么? dll版本号?我们可以抑制这一点并仅存储数据本身吗?
【问题讨论】:
标签: c++ serialization boost
这不是 Dll 版本。这是存档标题。
通过使用归档标志来抑制它:
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;
}
另见
【讨论】: