Created
July 15, 2011 10:23
-
-
Save roxlu/1084444 to your computer and use it in GitHub Desktop.
Remove particles from vector
This file contains 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
// create some particles. | |
for(int i = 0; i < 10; ++i) { | |
Particle p; | |
parts.push_back(p); | |
} | |
cout << "We have:" << parts.size() << " particles." << endl; | |
// remove some | |
vector<Particle>::iterator it = parts.begin(); | |
while(it != parts.end()) { | |
Particle& p = *it; | |
if(!p.alive) { | |
it = parts.erase(it); | |
cout << "die" << endl; | |
} | |
++it; | |
} | |
cout<< parts.size() << endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment