简体   繁体   中英

boost::property_tree::ptree serializing and deserializing

I am reading the xml file and storing into boost::property_tree::ptree pt(object).

I am trying to serialize this ptree object using the method serialize() defined in ptree_serialization.hpp

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

When i use above code i get the error as;

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> > >&]()))’

Could you please let me know if i am doing something wrong. Could you please let me know if we can serialize the xml parsed property ptree object.

You should use the archive interface as intended: doc

ar << pt;

or

ar >> pt;

The version is as configured using BOOST_CLASS_VERSION(Type, version) but that's in the implementation of Property Tree

Also remember to

#include <boost/property_tree/ptree_serialization.hpp>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM