exfo's suggestion will remove the compiler error, but it won't fix the logic.
At the moment your words are limited to 10 letters (which rules out "programming"!) and have to be separated by single spaces - there are plenty of other delimiters (various forms of punctuation etc.)
I would recommend inputting your line into a string (called 'line' below) using an alternative form of getline: getline( fin, line );
and breaking up line using string member functions (see the "Reference" section on this site).
I won't give you a whole solution, as that would constitute doing your homework.
Get each line of the file into a string (called, e.g., 'line') using my earlier suggestion. Write a for() loop to cycle through the characters of that string. The classic idiom for a new word is
- "new word if previous character was space and current character is not". The following function would achieve that:
You will have to loop through the characters of the line (having initialised oldc to a space for the first test and updated after each test).
If you want other criteria for new words (e.g. if you don't like an isolated number like 1 being counted as a new word you would have to include them in that function).
The advantage of having the whole line in a string is that it avoids problems with the carriage-return and new-line characters if you tried to read the text file character by character.
There are other techniques using string member functions.
Ah, I have to admit defeat! - exf0's solution would be better than mine, though you may have to change line 13 to ifstream fin(filename.c_str());
to make it adhere to the original C++ standard (string rather than const char* in the constructor added in C++11 according to this site).
Mind you, I managed to break both suggestions with a text.dat file containing
I don't know how to do this homework - let's ask ...
Here's another variant (stealing exf0's good ideas, but restricted to the original filename text.txt for simplicity). Numbers added to alphabet in the word validation so that Britain doesn't lose its most famous fictional secret agent!