谁能告诉我如何将迭代器增加 2?
Can anybody tell me how to increment the iterator by 2?
iter++
可用 - 我必须做 iter+2
吗?我怎样才能做到这一点?
iter++
is available - do I have to do iter+2
? How can I achieve this?
std::advance( iter, 2 );
此方法适用于不是随机访问迭代器的迭代器,但在与随机访问迭代器一起使用时,它仍然可以通过实现进行专门化,使其效率不低于 iter += 2
.
This method will work for iterators that are not random-access iterators but it can still be specialized by the implementation to be no less efficient than iter += 2
when used with random-access iterators.
这篇关于如何将迭代器增加 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!