| <<< std::map construction | Index | Looking at a map >>> |
Use operator[ ] to access items
map< string, int > agemap;
string name = "fred";
agemap[ name ] = 45; // "fred" --> 45
int age = agemap[ name ];
++agemap[ name ]; // now "fred" --> 46
Note: use of operator[ ] will put items in if they aren't there!
Generally, this is very useful, occasionally a pain.
map< string, int > visit_count;
string name = "fred";
++visit_count[ name ]; // Works fine!!
| <<< std::map construction | Index | Looking at a map >>> |