Original Post
Hi, i want to iterate through a list and want to delete an individual element.
i have tested this, code, but it crashes when i reach the element i erase:
what´s wrong here? If i use a vector instead of a list, with exactly the same code, it works!!
can anyone help me on this problem?
thanks
Gammastrahler
std::list<int> myList;
for (int i = 0; i < 10; i++)
myList.push_back(i);
std::list<int>::iterator iter;
for (iter = myList.begin(); iter != myList.end(); )
{
if ((*iter) == 4)
myList.erase(iter);
else
{
cout << (*iter) << endl;
iter++;
}
}