Hi I am trying to count the number of words in a file and this is what i have so far. I am not sure about the getchar().. could you please tell me what i should be doing ?
#include<iostream>
#include<fstream>
#include<string>
#include<conio.h>
using namespace std;
int main() {
string line;
int size=0, count_words=0;
char c;
ifstream myfile("example.rtf");
if(myfile.is_open()) {
while (!myfile.eof()) {
getline(myfile,line);
cout<<line<<endl;
size++;
}
cout<<"number of lines "<<size<<endl;
getchar(myfile,c);
cout<<c<<endl;
myfile.close();
}
else {
cout<<"file not found"<<endl;
}
return 0;
}