How to iterate a boost property tree?

前端 未结 5 716
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 03:27

I am know approaching to boost property tree and saw that it is a good feature of boost libs for c++ programming.

Well, I have one doubt? how to iterate a property t

5条回答
  •  太阳男子
    2020-12-24 04:08

    An addition to the answer How to iterate a boost property tree? :

    In the C++11 style range based for for (auto node : tree), each node is a std::pair

    Whereas in the manually written iteration

    Your_tree_type::const_iterator end = tree.end();
    for (your_tree_type::const_iterator it = tree.begin(); it != end; ++it)
    ...
    

    the iterator it is a pointer to such a pair. It's a tiny difference in usage. For example, to access the key, one would write it->first but node.first.

    Posted as a new answer, because my proposed edit to the original answer was rejected with the suggestion to post a new answer.

提交回复
热议问题