/*------------------------- concord.cc ------------------------------- Note: you may need to change this filename to concord.cpp or concord.C A concordance is a reference book which lists all the words in some corpus (such as the Bible or the works of Shakespeare). This simple concordance takes a text file (from standard input) and lists all the words (separated by white space) in the file in alphabetical order. You may supply input from the keyboard or from a text file: concord < textfile.txt This program makes use of classes from the Standard Library of C++: string and set. The latter is one of a family of collection classes from the Standard Template Library which has been incorporated into the C++ standard. A more useful concordance might use the STL's map class to keep track of additional information associated with each word in the input as well as make finer distinctions about word separators. Author: Glenn D. Blank, 3/31/98 -------------------------------------------------------------------*/ #include #include #include #include //In compilers that require use of namespaces to access the standard library, // uncomment the following: //using namespace std; //make names declared in std accessible in this scope //Need to instantiate a template for a set of strings template class set >; void main(int argc, char* argv[]) { set > concordance; //create concordance string word; //a word from input to store in concordance while (!cin.eof()) //up to end of file (ctrl-Z from DOS prompt) { cin >> word; //read a word up to a space, tab or new line concordance.insert(word); //insert word in concordance } //display concordance by copying from concordance to ostream copy(concordance.begin(),concordance.end(), ostream_iterator(cout,"\n")); }