Below is my code. I erase the element of which value is 3 and obtain next iterator by erase() function. But when I tried to print its value.It crashed to my surprise. Anyone know the problem??
int main()
{
std::vector<int> a = {1, 2, 3, 4, 5};
for(vector<int> ::iterator it=a.begin();it!=a.end();it++)
{
vector<int> ::iterator g;
if(*it==3 )
{
g=a.erase(it);
}
cout<<*g<<endl;
}