无法移动集合迭代器
Cannot move set iterator
我做错了什么:
set<int>::iterator beg = begin( my_set );
++beg;//<<here, no problem, as expected
beg += 3; //error here no += operator found?!
知道为什么吗?
推进迭代器的正确方法是使用std::advance
or std::next
beg = std::next(beg, 3);
std::advance(beg, 3);
由于指针运算,使用 +=
递增迭代器的方法将仅适用于数组(或具有 random access iterators 的容器)。
我做错了什么:
set<int>::iterator beg = begin( my_set );
++beg;//<<here, no problem, as expected
beg += 3; //error here no += operator found?!
知道为什么吗?
推进迭代器的正确方法是使用std::advance
or std::next
beg = std::next(beg, 3);
std::advance(beg, 3);
由于指针运算,使用 +=
递增迭代器的方法将仅适用于数组(或具有 random access iterators 的容器)。