boost :: property_tree :: ptree :: iterator确实定义了operator +

时间:2018-08-23 08:25:57

标签: boost

std :: XXX :: inerator始终支持operator +,例如

const string s = "abcdef";
cout << *(s.begin() + 3);//output d

但是ptree不支持operator +。

ptree p = root.get_child("insert");
//I want to directly goto the 3rd child.
auto iter = p.begin()+3;//error

我知道我可以使用for循环来做到这一点。但是我想知道是否还有一种更优雅的方式来做到这一点?

1 个答案:

答案 0 :(得分:-1)

我是通过以下方式实现的:

template <class InputIterator, class Distance>
  void advance (InputIterator& it, Distance n);

C++ stl advance document

auto iter = p.begin();
advance(iter, 3);
相关问题