Created
February 26, 2011 19:14
-
-
Save kybernetyk/845512 to your computer and use it in GitHub Desktop.
iterator muell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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