ric*_*d.g 1 c++ vector assertion
我在调试模式下运行我的代码,程序弹出一个断言失败的消息.请帮我找出导致此断言失败的部分.:{
Debug Assertion Failed!
Expression: vector iterators incompatible
Run Code Online (Sandbox Code Playgroud)
码:
int main()
{
vector<int> a(5);
fill(a.begin(), a.end(), 5);
a[2] = 3;
a[1] = 2; //so now a = {5,2,3,5,5}
auto it = a.begin();
for (; it != a.end();)
{
if (*it == 5)
a.erase(it); //Remove 5
else
it++;
}
copy(a.begin(), a.end(), ostream_iterator<int>(cout, "\n"));
}
Run Code Online (Sandbox Code Playgroud)