Sinux1

PS8Q8.cpp

May 3rd, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. bool spell_check(string user)
  7. {
  8.     bool flag = false;
  9.     ifstream compare;
  10.     string input = "dict.txt";
  11.     string file;
  12.  
  13.     compare.open(input.c_str());
  14.  
  15.     if (!compare)
  16.     {
  17.         cout << "File not found\n";
  18.         exit(0);
  19.     }
  20.     else
  21.     {
  22.         while(!(compare.eof()))
  23.            {
  24.               getline(compare, file);
  25.               if (user == file)
  26.                 {
  27.                   flag = true;
  28.                 }
  29.             }
  30.         compare.close();
  31.         return flag;
  32.     }
  33. }
  34.  
  35. int main()
  36. {
  37.     string word;
  38.  
  39.  
  40.     cout << "Enter word to spellcheck (or exit to end)\n";
  41.     getline(cin, word);
  42.     while (!(word == "exit"))
  43.  
  44.     {
  45.         if (spell_check(word))
  46.         {
  47.             cout << word << " is spelled correctly.\n";
  48.         }
  49.         else
  50.         {
  51.             cout << word << " is not spelled correctly.\n";
  52.         }
  53.  
  54.     cout << "Enter word to spellcheck (or exit to end)\n";
  55.     getline(cin, word);
  56.  
  57.     }
  58.     cout << "Ending program...\n";
  59.  
  60.     return 0;
  61. }
Add Comment
Please, Sign In to add comment