On 06-06-17 10:32, Lukas via Boost wrote:
boost::property_tree::ptree loadedJSON; boost::property_tree::read_json("animalList.json", loadedJSON); auto assoc_it = loadedJSON.find("animals"); auto it = loadedJSON.to_iterator(assoc_it); it = it->second.begin(); it++; // move to second item loadedJSON.erase(it); boost::property_tree::write_json("shorterList.json", loadedJSON);
You're using erase on the wrong container.
auto it = loadedJSON.to_iterator(assoc_it);
Here, it points into the root ptree.
it = it->second.begin();
Now, it points into the nested ptree ("animals")
loadedJSON.erase(it);
That's undefined behaviour. Fix:
#include