ok here is my code and the txt file contians
the dog goes bark
the cat goes meow
i would like to count the words but i have no clue how ??? can anyone help ??? i know i should know how to do this but i'm pointless and clueless on how to complete this task.... here is my code
Please help I need it desperatley...Code:#include <iostream.h> #include <fstream.h> #include "tstring.h" class WordCount { private: String word; ifstream infile; int count; public: void ReadStr(); void WriteStr(); int CountWords(); }; void WordCount::ReadStr() { infile.open("test.txt"); getline(infile, word, '\n'); //read first line of file } void WordCount::WriteStr() { cout << word << endl; //display first line of file while(getline(infile, word, '\n')) //read each line file one at a time { cout << word << endl; //displaying them as you go } } int WordCount::CountWords() { count = ' '; while(infile >> word) { count++; } cout << "The number words in the program are " << count << endl; } int main() { WordCount WC; char res; do { cout << "1 Read String." << endl; cout << "2 Print String." << endl; cout << "3 Count Words." <<endl; cout << "4 Exit." << endl; cout << "Please Select an operation: " << endl; cin >> res; switch(res) { case '1': WC.ReadStr(); break; case '2': WC.WriteStr(); break; case '3': WC.CountWords(); break; case '4': cout << "Thanks for using my program." << endl; exit(1); break; default: cout << "Invaild Option... Please Try again " << endl; } } while(res!='4'); }