C++ STL Vectors: Get iterator from index?(C++ STL 向量:从索引获取迭代器?)
问题描述
所以,我写了一堆代码,通过 index[] 访问 stl 向量中的元素,但现在我只需要复制向量的一个块.看起来 vector.insert(pos, first, last)
是我想要的函数......除了我只有 first 和 last 作为整数.有什么好的方法可以获得这些值的迭代器吗?
So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need to copy just a chunk of the vector. It looks like vector.insert(pos, first, last)
is the function I want... except I only have first and last as ints. Is there any nice way I can get an iterator to these values?
推荐答案
试试这个:
vector<Type>::iterator nth = v.begin() + index;
这篇关于C++ STL 向量:从索引获取迭代器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ STL 向量:从索引获取迭代器?


- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01