首页 > 代码库 > boost::archive::binary_iarchive

boost::archive::binary_iarchive

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <queue>
#include <boost/serialization/vector.hpp>
using namespace std;
struct MyStruct
{
    string stru;
    int len;
};
queue<MyStruct> q_stu;

void funa()
{
    MyStruct ms;
    int ret = 1;
    vector<int> vc;
    vc.push_back(1);
    vc.push_back(2);
    stringstream ss;
    boost::archive::binary_oarchive oa(ss);
    oa << ret << vc;
    ms.stru = ss.str();
    ms.len = ss.str().size();
    q_stu.push(ms);
}

void funb(const char* arg, int len)
{
    std::stringstream r_ss;
    r_ss.write(arg, len);
    boost::archive::binary_iarchive ia(r_ss);
    q_stu.pop();
    int ret;
    vector<int> vct;
    ia >> ret >> vct;
}


int main()
{
    funa();
    funb(q_stu.front().stru.c_str(), q_stu.front().len);
    getchar();
    return 0;
}