do
{
cout << " 1. Count Words In a File" << endl;
cout << " 2. Count Characters In a File" << endl;
cout << " 3. Sum Integers In a File" << endl;
cout << " 4. Average Integers In a File" << endl;
cout << " 5. Maximum Integers In a File" << endl;
cout << " 6. Minimum Integers In a File" << endl;
cout << " 7. Longest Word In a File" << endl;
cout << " 8. Quit" << endl;
cout << endl;
cout << "Choice : ";
cin >> choice;
cout << endl;
switch(choice)
{
case 1:
cout << " Enter the input file name : " << endl;
cin >> words;
count = CountWords(word, count);
if (count != 0)
{
cout << " Word Count = " << count << endl;
}
break;
case 8:
cout << "Thank you -- Goodbye!" << endl;
cout << endl;
break;
I can't remember exactly how to do it but the best way to count words for me is actually counting the spaces. So if you read one character at a time you can count all of the spaces, tabs, and new lines. But you have to do some error checking to handle 2 spaces next to each other but it should be relatively easy.
inf.unsetf(ios::skipws);
This makes it so when you read in a character it doesn't skip the spaces.