#include <string>
#include <map>
#include <iostream>

using namespace std;

int main()
{
  map<string,int> strings_to_ints;

  // Put some items into the map
  strings_to_ints["George"] = 3;
  strings_to_ints["Cathy"] = 6;
  strings_to_ints["Michelle"] = 8;

  // Get an item from the map
  cout << "Cathy's item is: " << strings_to_ints["Cathy"] << endl;

  // Create an iterator. We have to remember that when you iterate on
  // a map, you get *both* the key and the item in a data structure
  // called a "pair"
  map<string,int>::iterator a_string_and_int;

  // Look for an item in the map
  a_string_and_int = strings_to_ints.find("missing");

  if (a_string_and_int == strings_to_ints.end())
    cout << "\"missing\" isn't in the map." << endl;

  // Now find something that is in the map
  a_string_and_int = strings_to_ints.find("Cathy");

  // Double-check it
  if (a_string_and_int == strings_to_ints.end())
    cout << "Hm... STL didn't find the item?!" << endl;
  // We use .first to get the first element in the pair (the key),
  // and we use .second to get the second element (the item)
  else if ((*a_string_and_int).first != "Cathy" ||
           (*a_string_and_int).second != 6)
    cout << "Hm... STL didn't find the right item?!" << endl;
  else
    cout << "I found the item: " << (*a_string_and_int).first <<
      "->" << (*a_string_and_int).second << endl;

  // Now let's iterate over the items in the map
  cout << "The map is:" << endl;

  for (a_string_and_int = strings_to_ints.begin();
       a_string_and_int != strings_to_ints.end();
       a_string_and_int++)
    cout << (*a_string_and_int).first << "->" <<
      (*a_string_and_int).second << endl;

  return 0;
}

