2015-01-21 82 views
0

我正在讀取xml文件並存儲到boost :: property_tree :: ptree pt(object)中。boost :: property_tree :: ptree序列化和反序列化

我試圖使用ptree_serialization.hpp

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

定義當我上面的代碼我得到的誤差作爲使用的方法serialize()序列化此ptree中對象;

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對象。

+0

你能告訴我們你是如何定義'ar'和'pt'的嗎? – Arashium 2015-01-21 11:30:28

+0

ar可以是iarchive或oarchive對象。 pt被聲明爲boost :: property_tree :: ptree pt; – harshini 2015-01-21 11:31:57

+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 2015-01-21 12:01:59

回答

0

您應該使用按預期歸檔接口:doc

ar << pt; 

​​

版本作爲原料,BOOST_CLASS_VERSION(Type, version)配置,但是這是在財產的執行樹

還記得到

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

當我使用ar << pt錯誤:請求'val'中的成員'serialize',它是非類類型'boost :: property_tree :: basic_ptree ,std :: basic_string > *' – harshini 2015-01-21 13:17:42

+0

它說你正在序列化一個指針。 (這可能是正常的)。我認爲你錯過了包含(請參閱答案文本)。你***可以***嘗試'ar << * pt'雖然 – sehe 2015-01-21 13:19:56

+0

我包含#include ,但仍然收到錯誤錯誤:'struct boost :: property_tree :: basic_ptree < std :: basic_string ,std :: basic_string >'沒有名爲'serialize'的成員 – harshini 2015-01-22 04:40:38