Created
March 23, 2011 20:59
-
-
Save drbobbeaty/883960 to your computer and use it in GitHub Desktop.
Test of std::map Iterator invalidation on Ubuntu 10.04.1
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
#include "map" | |
#include "string" | |
#include "exception" | |
#include "iostream" | |
using namespace std; | |
int main(void) { | |
map<string, string> map_test; | |
map<string, string>::iterator iter_map_test; | |
map_test [ "AAAAA" ] = "11111"; | |
map_test [ "BBBBB" ] = "22222"; | |
map_test [ "CCCCC" ] = "33333"; | |
iter_map_test = map_test.find ("BBBBB"); | |
map_test.erase ("BBBBB"); | |
try { | |
string value = (*iter_map_test).second; | |
cout << "got : " << value << endl; | |
++iter_map_test; | |
cout << "next: " << (*iter_map_test).second << endl; | |
} catch ( exception & e ) { | |
cout << e.what() << endl; | |
} catch ( ... ) { | |
cout << "generic exception." << endl; | |
} | |
return(0); | |
} |
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
$ g++ maptest.cpp -o maptest | |
$ maptest | |
got : | |
next: 11111 | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment