the assignment is to count the number of words in a txt file here is my code
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
int main ()
{
string readIn;
string fileName;
int wordCount;
ifstream inFile;
wordCount = 0;
while (fileName != "quit")
{
cout << "enter file name"<<endl;
cin >> fileName;
inFile.open (fileName.c_str());
assert(inFile);
while (inFile)
{
inFile >> readIn;
wordCount++;
}
}
cout << wordCount;
return 0;
}
and here is the file
This &%file should!!,...
have exactly 7 words.
a word is defined byu any non-white space. every time i run it it gives me 8
instead
of 7, what am i doin wrong? please help, thanks/