I am using boost 1.55.0 on ubuntu 12.04lts with clang 3.4.
I have a boost::property_tree::ptree
whose xml input looks like:
<root>
<persons>
<person>
<name>dad</name>
<age>43</age>
</person>
<person>
<name>me</name>
<age>4</age>
</person>
</persons>
</root>
So I have a list of nodes with the same tag.
To read them I iterate over the tree, and depending on a condition I want to erase a node. This looks like:
boost::property_tree::ptree pt;
boost::property_tree::read_xml(inputFileName, pt);
boost::property_tree::ptree& persons = pt.get_child("root");
for(boost::property_tree::ptree::const_iterator it = persons.begin(); it != persons.end(); ++it)
{
std::string name = it->second.get<std::string>("name");
if(name == "dad")
// erase that name node from pt
persons.erase(it->second.find("name"); // this doesn't work
}
[Edit]As the answer from pmr supposes, I wrote the following code:
boost::property_tree::ptree::iterator i = persons.begin();
auto assoc_i = it->second.find("name");
auto ci = persons.to_iterator(assoc_i);
std::advance(i, std::distance<boost::property_tree::ptree::const_iterator>(iterator, ci)); // --> here it hangs
persons.erase(i);
Now it compiles, and the application does not crash, but it hangs at the mentioned position. And I don't know why. [/Edit]
Many thanks in advance.