int main(){
vector<int> veclist;
veclist.push_back(90);
veclist.push_back(80);
veclist.push_back(70);
vector<int>::iterator it;
it=veclist.begin();
veclist.insert(it,20);
cout << *it << endl; // prints 20
it++;
veclist.insert(it,99);
cout << *it <<endl; // line abc : prints 0
}
Hi, I am working with vectors and iterators in C++. In the above code, why is "line abc" printing 0. Shouldn't it be printing 99 instead? When I print all the vector elements using a for loop, 99 is also printed but why isn't line abc doing so? I am dereferencing the iterator *it, and I expected it to hold the element 99.