Boost 1.46.1, Property Tree: How to iterate through ptree receiving sub ptrees?
Using C++11, you can use the following to iterate through all the children of the node at path
:
ptree children = pt.get_child(path);
for (const auto& kv : children) {
// kv is of type ptree::value_type
// kv.first is the name of the child
// kv.second is the child tree
}
The property tree iterators point to pairs of the form (key, tree)
of type ptree::value_type
. The standard loop for iterating through the children of the node at path
therefore looks like:
BOOST_FOREACH(const ptree::value_type &v, pt.get_child(path)) {
// v.first is the name of the child.
// v.second is the child tree.
}