Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
spell.cpp
Go to the documentation of this file.
1
29#include <fstream>
30#include <iostream>
31#include <iterator>
32#include <set>
33#include <string>
34
35#include <examples.h>
36
37
38typedef
39 std::set <std::string,
40 std::less<std::string>, std::allocator<std::string> > stringset;
41typedef
42 std::ostream_iterator<std::string,
43 char, std::char_traits<char> > ostrm_iter;
44typedef
45 std::istream_iterator<std::string,
46 char, std::char_traits<char>,
47 std::ptrdiff_t> istrm_iter;
48
49
50void spellCheck (std::istream & dictionary, std::istream & text) {
51
52 stringset words, misspellings;
53 std::string word;
54 istrm_iter eof, dstream (dictionary);
55
56 // First read the dictionary.
57 std::copy (dstream, eof, std::inserter (words, words.begin ()));
58
59 // Next read the text.
60 while (text >> word)
61 if (! words.count (word))
62 misspellings.insert (word);
63
64 // Finally, output all misspellings.
65 std::cout << std::endl << "Misspelled words:" << std::endl;
66
67 std::copy (misspellings.begin (), misspellings.end (),
68 ostrm_iter (std::cout, "\n"));
69}
70
71int main ()
72{
73 std::cout << "Enter text:";
74 std::ifstream words ("words");
75 spellCheck (words, std::cin);
76 std::cout << "End of spell check program" << std::endl;
77 return 0;
78}
std::istream_iterator< std::string, char, std::char_traits< char >, std::ptrdiff_t > istrm_iter
Definition spell.cpp:47
std::set< std::string, std::less< std::string >, std::allocator< std::string > > stringset
Definition spell.cpp:40
void spellCheck(std::istream &dictionary, std::istream &text)
Definition spell.cpp:50
int main()
Definition spell.cpp:71
std::ostream_iterator< std::string, char, std::char_traits< char > > ostrm_iter
Definition spell.cpp:43