使用boost库在队列和堆栈数据结构上保存和加载数据时出错 [英] Error on save and load data on queue and stack data structures using boost library
问题描述
我是使用boost序列化库的新手。
我想使用text_iarchive和text_oarchive在STL结构中保存和加载数据。
我用下面的代码:
I am new in using boost serialization library.
I want to save and load data to and from STL structures using text_iarchive and text_oarchive.
I used bellow code for that:
mystruct test;
test.initial();
{
std::ofstream ofs("filename.dat");
boost::archive::text_oarchive ar(ofs);
ar & test;
}
{
std::ifstream ifs("filename.dat");
boost::archive::text_iarchive ar(ifs);
mystruct restored;
ar & restored;
}
我的尝试:
在map,list,deque,set和vector上没有任何问题,但是在队列和堆栈上我得到以下错误:
错误:没有匹配函数用于调用'save (boost :: archive :: text_oarchive&,const std :: deque>&,const unsigned int&)'
错误:没有匹配函数来调用'load(boost :: archive: :text_iarchive&,std :: deque>&,const unsigned int&)'
如何解决这个问题?
What I have tried:
On map, list, deque, set and vector there isn't any problem but on queue and stack I get following errors:
error: no matching function for call to 'save(boost::archive::text_oarchive&, const std::deque >&, const unsigned int&)'
error: no matching function for call to 'load(boost::archive::text_iarchive&, std::deque >&, const unsigned int&)'
How can I solve this problem?
推荐答案
昨天我发现了一些东西,当我使用cout打印我的结构时它起作用Okey。但是当我想从文件中读取和写入时,只有使用堆栈和队列才会出现此问题。第二,我之前在main函数中使用了头文件进行序列化,但是当我将这些头文件用于我的队列和堆栈类时,问题就解决了。有线!
当我使用此订单时出现错误:
yesterday I found out something first when I use cout for printing my structure it works Okey. but when I want to read and write from file this happens, this problem occurs only with use of stack and queue. At second, I used headers for serialization in main function before, but when I use that headers for my queue and stack class the problem solved. its wired !
when I used this order of header those errors appeared:
#include <boost/serialization/vector.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/queue.hpp>
#include <boost/serialization/stack.hpp>
#include <boost/serialization/deque.hpp>
但是当我用这个问题解决了:
but when I used this problem solved:
#include <boost/serialization/vector.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/deque.hpp>
#include <boost/serialization/queue.hpp>
#include <boost/serialization/stack.hpp>
这篇关于使用boost库在队列和堆栈数据结构上保存和加载数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!