Removing an iterator (iterator first, iterator last) doesn't work in Visual C ++ 2010 Express

I found a problem while writing code in Visual C ++ 2010 Express. When I execute the last line, I get a runtime error: "vector iterator cannot be dereferenced". What's wrong with the code below?

vector<int> vec (5, 1001);

vector<int>::iterator begin = vec.begin();
vector<int>::iterator end = vec.begin();

begin++; //std::advance(begin, 1); gives the same result
end++; end++; end++; //std::advance(end, 3); gives the same result

cout << (*begin) << endl;
cout << (*end) << endl;
begin = vec.erase(begin, end);
cout << (*begin) << endl;              //It doesn't work

      

This code is run by gcc. When the items are erased one by one, it also works in VC ++ 2010 Express.

Is this a bug in VC ++ 2010 Express?

+3


source to share


1 answer


If you are not using SP1 then this VC10 bug may have struck you, there is also some workaround in there.



+3


source







All Articles