
#include <map>
#include <string>
#include <iostream>
using namespace std;

int main()
{
    // declare a string->int map
    map<string, int> table;
    
    // insert key, value pair
    table["foo"] = 1;
    table["bar"] = 20;
    
    // print out
    cout << table["foo"] << endl;
    cout << table["bar"] << endl;
    // this inserts ("jojo", 0)
    cout << table["jojo"] << endl;
    
    // query
    if( table.find( "aaa" ) == table.end() )
    {
        cout << "cannot find aaa" << endl;
    }
    
    // iterate the map
    map<string, int>::iterator iter;
    for( iter = table.begin(); iter != table.end(); iter++ )
    {
        // print the pair
        cout << iter->first << " " << iter->second << endl;
    }
    
    // remove element from map
    cout << "erase returned: " << table.erase( "jojo" ) << endl;

    return 0;
}
