c++ - Boost 1.46.1, Property Tree: How to iterate through ptree receiving sub ptrees? -



c++ - Boost 1.46.1, Property Tree: How to iterate through ptree receiving sub ptrees? -

first of shall think got how should done code not compile way try. based assumption on this official illustration of empty ptree trick. there can find next line:

const ptree &settings = pt.get_child("settings", empty_ptree<ptree>());

which shows (or should be) possible subptree out ptree.

so assumed iterate thru ptree boost_foreach in such manner:

boost_foreach(const boost::property_tree::ptree &v, config.get_child("servecies")) { }

but next error:

error 1 error c2440: 'initializing' : cannot convert 'std::pair<_ty1,_ty2>' 'const boost::property_tree::ptree &'

or if seek

boost_foreach(boost::property_tree::ptree &v, config.get_child("servecies", boost::property_tree::empty_ptree<boost::property_tree::ptree>())) { }

i get:

error 1 error c2039: 'empty_ptree' : not fellow member of 'boost::property_tree'

so shall do: how iterate thru boost ptree , sub ptrees?

update: tried such code

boost_foreach(boost::property_tree::ptree::value_type &v, config.get_child("path.to.array_of_objects")) { std::cout << "first data: " << v.first.data() << std::endl; boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second ; boost_foreach(boost::property_tree::ptree::value_type &vs, subtree) { std::cout << "sub data: " << vs.first.data() << std::endl; } }

this compiles, not throw exeptions not cout sub data, skeeps thru cycle.

update 2:

hm... went wrong in xml - right results code.

the property tree iterators point pairs of form (key, tree) of type ptree::value_type. standard loop iterating through children of node @ path hence looks like:

boost_foreach(const ptree::value_type &v, pt.get_child(path)) { // v.first name of child. // v.second kid tree. }

c++ boost subtree boost-propertytree boost-foreach

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -