home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / SPELL.CPP < prev    next >
C/C++ Source or Header  |  1997-02-14  |  1KB  |  45 lines

  1. /**************************************************************************
  2.  *
  3.  * spell.cpp -  spell checking program.  Section 8.3
  4.  *
  5.  * $Id: spell.cpp,v 1.4 1995/08/29 19:03:32 oberg Exp $
  6.  *
  7.  * $$RW_INSERT_HEADER "slyrs.cpp"
  8.  *
  9.  **************************************************************************/
  10.  
  11. # include <set>
  12. # include <string>
  13. # include <fstream.h>
  14. using namespace std;
  15.  
  16. void spellCheck (istream & dictionary, istream & text)
  17. {
  18.     typedef set <string, less<string> > stringset;
  19.     stringset words, misspellings;
  20.     string word;
  21.     istream_iterator<string, ptrdiff_t> dstream(dictionary), eof;
  22.  
  23.         // first read the dictionary
  24.     copy (dstream, eof, inserter(words, words.begin()));
  25.  
  26.         // next read the text
  27.     while (text >> word)
  28.         if (! words.count(word))
  29.             misspellings.insert(word);
  30.  
  31.         // finally, output all misspellings
  32.     cout << "Misspelled words:" << endl;
  33.     copy (misspellings.begin(), misspellings.end(),
  34.         ostream_iterator<string>(cout, "\n"));
  35. }
  36.  
  37. int main()
  38. {
  39.     cout << "Enter text:";
  40.     ifstream words("words");
  41.     spellCheck(words, cin);
  42.     cout << "End of spell check program" << endl;
  43.     return 0;
  44. }
  45.