C++ STL Vectors: Get iterator from index?

mpen picture mpen · Mar 22, 2009 · Viewed 138.5k times · Source

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?

Answer

dirkgently picture dirkgently · Mar 22, 2009

Try this:

vector<Type>::iterator nth = v.begin() + index;