Skip to content

Instantly share code, notes, and snippets.

@kybernetyk
Created February 26, 2011 19:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kybernetyk/845512 to your computer and use it in GitHub Desktop.
iterator muell
std::vector<int> x;
x.push_back(1);
x.push_back(2);
x.push_back(3);
x.push_back(4);
x.push_back(5);
x.push_back(3);
x.push_back(5);
std::vector<int>::iterator it = x.begin();
printf("erster lauf mit erase: \n");
while (it != x.end())
{
int i = *it;
printf("%i\n", i);
if (i == 3)
{
x.erase(it);
continue;
}
++it;
}
printf("\nzweiter lauf:\n");
it = x.begin();
while (it != x.end())
{
printf("%i\n", *it);
++it;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment