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?
If your not using SP1 then this VC10 bug might have hit you, there is also some kind of workaround listed there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With