How to insert an element into a vector at a particular index

I am storing info in a vector but I want to store certain info at a particular index. I am new to using vectors and am unsure about have to do this. I am aware of the insert method but am confused on how to use it to store at a particular index. Any advice on this matter is greatly appreciated.

Thanks In Advance
The insert function takes an iterator as argument to decide the position in the vector to place the new element. You can use the begin function to get an iterator to the first element in the vector, and if you add the index to the iterator you'll get an iterator to the element at the index.
vec.insert(vec.begin() + index, elem);
Last edited on
Topic archived. No new replies allowed.