本文介绍了如何在boost serialization :: archive中抑制多余的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在序列化的Boost代码示例中公交时刻表在其输出文件"demofile.txt"中,第一行是:

In the example of Boost code of serializationbus schedulein its output file "demofile.txt" the first line is:

"22 serialization::archive 16 0 0 6 0 0 0 0 0 6 24 4"

这是什么?dll版本号?我们可以抑制这种情况,只存储自身的数据吗?

what is this? Dll version number? Can we suppress this and store only the data itsself?

推荐答案

这不是Dll版本.这是存档标题.

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;
}

另请参见

这篇关于如何在boost serialization :: archive中抑制多余的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:36