<<< map::erase | Index | std::multimap >>> |
A
The elements in std::map are always sorted by its keys.
Each element of the map is formed by the combination of the key value and a mapped value.
Map iterators access both the key and the mapped value at the same time.
#include <cassert> #include <iostream> #include <string> #include <map> using namespace std; int main (int argc, char* argv[]) { map< string, string > phone_book; phone_book[ "411" ] = "Directory"; phone_book[ "911" ] = "Emergency"; phone_book[ "508-678-2811" ] = "BCC"; if ( phone_book.find( "411" ) != phone_book.end() ) { phone_book.insert( make_pair( string( "411" ), string( "Directory" ) ) ); } assert( phone_book.size() == 3 ); map< string, string >::const_iterator it; for ( it = phone_book.begin(); it != phone_book.end(); ++it ) { cout << " " << it->first << " " << it->second << endl ; } return 0; } /* Output: 411 Directory 508-678-2811 BCC 911 Emergency */
<<< map::erase | Index | std::multimap >>> |