Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created July 15, 2011 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roxlu/1084444 to your computer and use it in GitHub Desktop.
Save roxlu/1084444 to your computer and use it in GitHub Desktop.
Remove particles from vector
// 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