// Example program : concordance, using STL container classes // i.e. for each word, print a list of all pages where it appears using namespace std; #include // the standard string library #include // for cout #include #include int main(){ int foo(3); {// beginning of block // create empty concordance: map > concordance; // add some entries to it: concordance["apple"].push_back(foo++); concordance["lemon"].push_back(foo++); concordance["apple"].push_back(foo++); concordance["apple"].push_back(foo++); concordance["lemon"].push_back(foo++); // dump the contents of the concordance: for (map >::const_iterator wordlist = concordance.begin(); wordlist != concordance.end(); wordlist++){ // print the word: cout << wordlist->first << " : "; // print the list of all pages where it appears for (list::const_iterator page = wordlist->second.begin(); page != wordlist->second.end(); page++) { cout << *page << " "; } cout << endl; } }// end of block; all memory used by the concordance has been freed // more processing ... // and more ..... }