How to increment an iterator by 2?(如何将迭代器增加 2?)
问题描述
谁能告诉我如何将迭代器增加 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将迭代器增加 2?
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
