4

Is there an easy to delete a child (and its eventual subchildren) from a property tree that is known via its path?

The following

auto child = ptree.get_child(path);
child.clear();

does not actually remove the child, but only its content.

The erase member function takes an iterator or a key. I don't know of an easy way to find the iterator corresponding to a path, without having to iterate through the tree.

One could find the "root" children by by splitting the path at dot characters, and eraseing the remaining. However is there any easier/shorter way of getting there?

P-Gn
  • 23,115
  • 9
  • 87
  • 104

1 Answers1

4

You could do this:ptree.get_child("path.to").erase("child"); Note that this deletes ALL nodes named "child" within the path "path.to" and their subchildren.

Marste
  • 627
  • 7
  • 22