boost property tree, iterators to an element for inserting?

戏子无情 提交于 2019-12-01 11:27:37

问题


I've searched a lot through the boost manual, and the internet, as I believe it is quite a standard feature?

Well I'm looking into "merging" property trees. - I noticed the function insert, and I hope I can merge trees with this? Below is the line which I am trying to get working:

base.insert(base.get_child("BRANCH"), t);

base and t are "property trees", base has as (one of many) branch "BRANCH". Now I wish to insert t into this branch?
More specifically: how can I get an iterator to "element" if I know that element by name?


回答1:


You can get an iterator to an element using the begin() method:

  base.get_child("BRANCH").begin();

In order to insert every element in t on that position, you should use:

base.insert(base.get_child("BRANCH").begin(), t.begin(), t.end());

If t contains one parent node or you only want to insert the first node, you can use:

base.insert(base.get_child("BRANCH").begin(), t.front());


来源:https://stackoverflow.com/questions/7590370/boost-property-tree-iterators-to-an-element-for-inserting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!