ThomasN
ThomasN

Reputation: 94

iterator erase (iterator first, iterator last) doesn't work under Visual C++ 2010 Express

I've found a problem while writing code under Visual C++ 2010 Express. When executing last line I get a runtime error "vector iterator not dereferencable". What is 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 works under gcc. When elements are erased one by one it works in VC++ 2010 Express too.

Is it a bug in VC++ 2010 Express?

Upvotes: 3

Views: 214

Answers (1)

Surt
Surt

Reputation: 16109

If your not using SP1 then this VC10 bug might have hit you, there is also some kind of workaround listed there.

Upvotes: 4

Related Questions