【问题标题】:how to suppress the extra information in boost serialization::archive?如何抑制 boost serialization::archive 中的额外信息?
【发布时间】: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


    【解决方案1】:

    这不是 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;
    }
    

    另见

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 2014-02-14
      • 2012-04-15
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多