Segfault on inserting into std::vector with insert member function of std::vector

When I insert into the vector like this :

resVec.insert(frontIter , vec[idx]);

I get a seg fault , but if I do

*frontIter = vec[idx];

It works without any problems. I know that the []operator has the capacity to allocate space for the object and then insert it, is the error that insert does not allocate space and it needs the space to be already allocated when insert is called at a position ?

I think this error is due to my confusion about what this does :

vi vec(10);

Is this similar to

vec.resize(10)

or

vec.reserve(10)

Also does insert not work as say position 9 after I have called vec.reserve(10) ?

This is the code segment, just to make sure that I am not missing anything.

Error is due to invalidation of iterator frontIter after first insert is happened. Here is whats going on:

Code allocate vector vec with 10 elements in it.

New element is inserted into position frontIter, this trigger vector storage re-allocation because vector out of it capacity so insert code reallocate inner storage to accommodate the insert. So this operation invalidate allvec iterators

Code try to insert new element by using old (invalidated) iterator... - seg-fault!