gpt4 book ai didi

c++ - boost::property_tree::ptree 序列化和反序列化

转载 作者:行者123 更新时间:2023-11-30 05:48:46 26 4
gpt4 key购买 nike

我正在读取 xml 文件并存储到 boost::property_tree::ptree pt(object) 中。

我正在尝试使用在 ptree_serialization.hpp 中定义的方法 serialize() 序列化此 ptree 对象

boost::property_tree::serialize(ar,pt,1);

当我使用上面的代码时,我得到的错误是;

boost/serialization/collections_save_imp.hpp:64:9: error: no match for ‘operator<<’ in ‘ar << boost::serialization::make_nvp(const char*, T&) [with T = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >]((* &((boost::iterator_facade<boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, boost::bidirectional_traversal_tag, const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, int>*)(& boost::operator++ [with I = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, V = std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, TC = boost::bidirectional_traversal_tag, R = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, D = int, typename boost::detail::postfix_increment_result<I, V, R, TC>::type = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator]((*(boost::iterator_facade<boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, boost::bidirectional_traversal_tag, const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, int>*)(& it)), 0)))->boost::iterator_facade<I, V, TC, R, D>::operator* [with Derived = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, Value = std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, CategoryOrTraversal = boost::bidirectional_traversal_tag, Reference = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, Difference = int, boost::iterator_facade<I, V, TC, R, D>::reference = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&]()))’

如果我做错了什么,你能告诉我吗?如果我们可以序列化 xml 解析的属性 ptree 对象,请告诉我。

最佳答案

您应该按预期使用存档界面:doc

ar << pt;

ar >> pt;

版本是使用 BOOST_CLASS_VERSION(Type, version) 配置的,但这是在 Property Tree 的实现中

还记得

#include <boost/property_tree/ptree_serialization.hpp>

关于c++ - boost::property_tree::ptree 序列化和反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28065987/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com