Skip to content

Instantly share code, notes, and snippets.

@zachelko
Created April 11, 2010 05:10
Show Gist options
  • Save zachelko/362514 to your computer and use it in GitHub Desktop.
Save zachelko/362514 to your computer and use it in GitHub Desktop.
STL begin() 2
std::vector<int> foo;
// Add an item before setting the iterator...
// Should work, right?
foo.push_back(2);
std::vector<int>::iterator iter = foo.begin();
// Add another item
foo.push_back(3);
// Use the iterator... oops!
while (iter != foo.end()) {
std::cerr << *iter << "\n";
++iter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment