Skip to content

Instantly share code, notes, and snippets.

@moxuse
Last active October 13, 2015 17:27
Show Gist options
  • Save moxuse/4230241 to your computer and use it in GitHub Desktop.
Save moxuse/4230241 to your computer and use it in GitHub Desktop.
map挿入、検索、削除
/////////////// insert
users.insert( map<string, UserClass>::value_type( str, UserClass( args.. ) ) );
////////// loop access
map<string, UserClas>::iterator it = users.begin();
while( it != users.end() ) {
cout << "key : " << (*it).first << " value : " << (*it).second << endl;
++it;
}
/////////////// search
map<string, UserClass>::iterator it = users.begin();
while( it != users.end() ) {
string key = (*it).first;
if ( users.end() != users.find( key ) ) { //or if ( "KEY" == key )
cout << "key : " << (*it).first << " value : " << (*it).second << endl;
}
++it;
}
//////////////// erase
map<string, UserClass*>::iterator it = users.begin();
while( it != users.end() ) {
string key = (*it).first;
if ( users.end() != users.find( key ) ) {
users.erase(it++);
cout << "erase __ : " << key << endl;
break;
} else {
++it;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment