You are accessing an unitialised variable (the iterator
itr1
) with the dereference operator (
*
).
To let the iterator point to a specific vector element add the index to the iterator pointing to the begin of the vector:
itr1 = vec.begin() + 4;
vec.erase(itr1);
Alternatively use
advance - C++ Reference[
^]:
itr1 = vec.begin();
std::advance(itr1, 4);
vec.erase(itr1);