如何在boost::序列化中遍历归档
How to iterate over archive in boost::serialization
我加载了多个数据到boost::archive::text_oarchive
,现在我需要提取这些数据。但是因为存档包含多条记录,所以我需要一个迭代器。
//input archive
boost::archive::text_iarchive iarch(ifs);
//read until the end of file
while (!iarch.eof()){
//read current value
iarch >> temp;
...//do something with temp
}
是否有任何标准的方法来遍历存档的元素?我只找到了iarchive.iterator_type
,但它是我需要的吗?我怎么使用它?
您要查看的迭代器类型实际上来自
class shared_ptr_helper {
...
typedef std::set<
boost::shared_ptr<const void>,
collection_type_compare
> collection_type;
typedef collection_type::const_iterator iterator_type;
,我认为它是在存档加载期间使用的,而不是外部使用的迭代器。
如果您查看tutorial -> STL Collection下的链接http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/index.html,您将看到以下示例:
#include <boost/serialization/list.hpp>
class bus_route
{
friend class boost::serialization::access;
std::list<bus_stop *> stops;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & stops;
}
public:
bus_route(){}
};
如果这不是你所需要的,那么你可能需要根据http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/tutorial.html#splitting查看重载加载和保存并根据需要添加处理
相关文章:
- 有什么方法可以遍历结构吗
- 如何在C++中序列化结构数据
- 在循环中按顺序遍历成员变量
- 序列化,没有库的整数,得到奇怪的结果
- 如何知道QDataStream不能反序列化某些内容
- 遍历模板参数
- 在遍历处理程序的向量时注册和注销处理程序
- 如何使用Python从C++中读取谷物序列化数据
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 自定义对象的dlib序列化在gcc中失败
- C++boost序列化多态性问题
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 结构化绑定:遍历元组的双端面
- c++列表遍历和初始化
- 创建并遍历一个模板化对象数组
- 在修改序列时遍历该序列.使用向量还是列表?c++ STL
- 如何在boost::序列化中遍历归档
- 计算序列中元素的平均值,而不遍历它
- 可视化如何做我遍历 std::map<std::string,shared_ptr<A>> 在 C++ 中的元素