2015-01-21 4 views
0

Я читаю xml-файл и сохраняю его в boost :: property_tree :: ptree pt (object).boost :: property_tree :: сериализация и десериализация ptree

Я пытаюсь сериализации этого объекта Ptree с использованием методы serialize(), определенной в ptree_serialization.hpp

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

Не могли бы вы сообщить мне, если я делаю что-то неправильно. Не могли бы вы сообщить мне, если мы сможем сериализовать объект ptree объекта parsed xml.

+0

Не могли бы вы рассказать нам, как вы определили 'ar' и' pt'? – Arashium

+0

ar может быть либо iarchive, либо oarchive object. pt объявляется как boost :: property_tree :: ptree pt; – harshini

+0

Я не эксперт в этой области. 'boost :: property_tree :: ptree pt (object)' кажется отсутствием шаблона: ''. я думаю, что 'serialize' нуждается в типе' basic_ptree' для второго аргумента в соответствии с его исходным кодом: http://www.boost.org/doc/libs/1_42_0/boost/property_tree/ptree_serialization.hpp. Также см .: http://codereview.stackexchange.com/questions/1818/. см., если они помогают – Arashium

ответ

0

Вы должны использовать интерфейс архива по назначению: doc

ar << pt; 

или

ar >> pt; 

Эта версия также конфигурируется с помощью BOOST_CLASS_VERSION(Type, version), но это в реализации имущества Дерево

Также помните, до

#include <boost/property_tree/ptree_serialization.hpp> 
+0

. Я получаю ниже ошибки при использовании ar << pt error: запрос для члена 'serialize' в 'val', который имеет тип non-class 'boost :: property_tree :: basic_ptree , std :: basic_string > * ' – harshini

+0

В нем говорится, что вы сериализуете указатель. (Это может быть нормально). Я _think_ вам не хватает include (см. Текст ответа). Вы *** можете *** попробовать 'ar << * pt' хотя – sehe

+0

Я включил #include , и все же я становлюсь ниже ошибки ошибки: 'struct boost :: property_tree :: basic_ptree < std :: basic_string , std :: basic_string > 'не имеет имени с именем' serialize ' – harshini

Смежные вопросы