我知道我们可以使用boost :: serialization for std :: vector,list,map等,只要我包含相应的boost头文件,如:
#include <boost/serialization/list.hpp>
但是我如何使用boost :: serialization for std :: stack?
由于
答案 0 :(得分:0)
将std::stack
替换为std::deque
并包含:
#include <boost/serialization/deque.hpp>
答案 1 :(得分:0)
我知道这很旧,但是最近遇到了这个问题。我对使用std :: deque的解决方案不满意,因为我真的只需要 一个堆栈接口。当前,通过按顺序包含这些头文件
来增强对std :: stack的序列化支持#include "boost/serialization/deque.hpp"
#include "boost/serialization/stack.hpp"
完整的示例如下:
#include <string>
#include <stack>
#include "boost/archive/text_oarchive.hpp"
#include "boost/archive/text_iarchive.hpp"
#include "boost/serialization/deque.hpp"
#include "boost/serialization/stack.hpp"
struct s
{
std::stack<std::string> stack;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & stack;
}
};