- Code: Select all
/* Count Words program
Pre: InFile contains a a string.
Post: returns number of words and average word length of InFile */
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
main() {
string word;
ifstream InFile;
int i = 0;
InFile.open("source.txt");
while(InFile >> word) {
i++;
}
cout <<"Total Words: "<< i << '\n';
return 0;
}
Thanks for your help everybody!
