int main() { Thesaurus thesaurus; // Fill with 10 entries: generate_n( inserter(thesaurus, thesaurus.begin()), 10, ThesaurusGen()); // Print everything: copy(thesaurus.begin(), thesaurus.end(), ostream_iterator<TEntry>(cout, "\n")); // Ask for a "word" to look up: while(true) { cout << "Select a \"word\", 0 to quit: "; for(TIter it = thesaurus.begin(); it != thesaurus.end(); it++) cout << (*it).first << ' '; cout << endl; string reply; cin >> reply; if(reply.at(0) == '0') return 0; // Quit if(thesaurus.find(reply) == thesaurus.end()) continue; // Not in list, try again vector<string>& v = thesaurus[reply]; copy(v.begin(), v.end(), ostream_iterator<string>(cout, " ")); cout << endl; } } ///:~
// Ask for a "word" to look up: string menu(Thesaurus &thesaurus) { while(true) { cout << "Select a \"word \" , 0 to quit: "; for(TIter it = thesaurus.begin(); it != thesaurus.end(); it++) cout << (*it).first << ' '; cout << endl; string replay; cin >> replay; if(replay.at(0) == '0') exit(0); if(thesaurus.find(replay) == thesaurus.end()) continue; // Not in list, try again return replay; } }