I'm in the middle of a program assignment and I'm getting an error I don't quite understand.
Here are the tasks it must accomplish.
1. Open the file containing the word list and read all the words into a 1D vector of strings. Close the file when complete.
2. Prompt the user with a menu.
Option 1 should allow the user to check for the existence of a word in the file.
Option 2 should allow the user to quit the program.
Sanitize the input (make sure it doesnʼt break the program). If the user maliciously types a
character string at a numeric prompt, your program should be able to ignore it and recover!
Check for any errors which you can handle!
3. Implement a function which accepts the word list and the search word. This function should
traverse the vector. If it finds the word, the function should immediately return true. If it does not find the word, the function should return false.
Here is my source code so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# include <iostream>
# include <iomanip>
# include <fstream>
# include <vector>
using namespace std;
int ShowMenu();
vector <string> OpenFile();
int main()
{
ShowMenu();
OpenFile();
return 0;
}
int ShowMenu()
{
int choice;
cout << "\t" << "Menu:" << endl << endl
<< "\t" << "\t" << "1. Check for Word" << endl
<< "\t" << "\t" << "2. Quit" << endl;
cin >> choice;
if (choice==2)
{
return 0;
}
else if (choice==1)
{
cout << "Checking...";
}
else
{
cout << "Unavailable choice. Please restart.";
}
}
vector<string> OpenFile()
{
vector<string> words;
ifstream fin;
fin.open("Wordlist");
cout << "WordList is now open";
int i;
while (!fin.eof())
{
fin >> words(i);
i++;
}
return words;
}
| |
Here's the error I am receiving at compile time.
In function `std::vector<std::string, std::allocator<std::string> > OpenFile()':
51: error: no match for call to `(std::vector<std::string, std::allocator<std::string> >) (int&)'
Any help with this error and the next tasks would be much appreciated.
Thanks.