#include #include #include using namespace std; int main() { // The map data structure is an associative container // that maps one data type to another (e.g. string to int) // e.g. map "the" to 140 "the" ==> 140 // e.g. map "Achilles" to 6 "Achilles" ==> 6 // key , value map< string, int > words; // other examples: // map< int, vector > m1; // maps int keys to vectors-of-strings // map< int, Word_Node > m2; // map< string, Word_Node > m3; // e.g. in the Word_Node class, we might // // have count, vector indexes, // // snippets // map< Student, vector > m4; string w; while ( cin >> w ) { // the key is specified in [key] words[w] = words[w] + 1; // words[s]++; // the operator[] function is important } // use an iterator to iterate through the elements of the map // and display them map< string, int >::const_iterator i = words.begin(); while ( i != words.end() ) { // key value cout << i->first << " (count: " << i->second << ")\n"; i++; } return 0; }