#include #include #include "CPstring.h" // file: wordcount2.cc // author: D. Ramm // date: 10/11/96 // file input in while test // counting words int main() { int wcount = 0; int charcnt = 0; string word, filename; ifstream file; cout << "Enter file name: "; cin >> filename; file.open(filename); while (file >> word) { wcount++; charcnt += word.length() + 1; } cout << "Word count is " << wcount << endl; cout << "Estimated character count is " << charcnt << endl; return 0; } Sample output: wordcount2 Enter file name: wordcount2.cc Word count is 87 Estimated character count is 503