C++ STL 向量:从索引中获取迭代器?

2022-01-10 00:00:00 iterator vector 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;

相关文章