1 2 3 4 5 6 7 8 9 10 11 12
|
//Get the filename.
cout << "Enter the file you wish to have searched:\n";
cin >> filename;
// right
// Open file.
ifstream file(filename.c_str());
// right
// Read in all the words.
string word;
// not really, no
|
If the words in the file are on different lines, which is usually the case, you read the file line by line and input the words into an array of strings. I propose you use
std::vector<std::string> a
for reason apparent later.
Now, you create another vector
b of strings to hold distinct words, and another vector
c that serves as a counter. You iterate over the elements of
a, if an element is identical to the one before it, increment the corresponding cell in
c, else, push it to
b and push
1 to
c...
This is the general idea. Try working that out.
HINT: How do you look for a word in the dictionary?