i am currently workin through the thinking in c++ ebook 2nd edition, at the end of the 2nd chapter i get the following taski:::
Create a program that opens a file and counts the whitespace-separated words in that file....
this is the program i wrote, but i just dont think this s right... is there any keyword that i can use to count words? (i know i can use strlen, but that would only give number of caghracters and not words???)
Code:#include<vector> #include<fstream> #include<iostream> #include<string> using namespace std; int main() { vector<string> vect; string norm; cout<<"This program will count the words in a file.\n"; ifstream count("exe3.txt"); while(count>>norm) vect.push_back(norm); for(int ln=0;ln<vect.size();ln++) cout<<ln<<": "<<vect[ln]<<endl; cin.get(); }