im trying to figure out how i count the number of 5 letter words in a file and the number of 6 or greater words in the same file using a string. all the examples are at higher level of programming im just a beginner. my books very briefly tells me how to count characters and not words. but from that i got this and my output just says the number of words is: 1. could i get the basic syntax on how to count words in a text file in c++
ifstream infile;
//char mystring[6];
//char mystring[20];
int main()
{
infile.open("file.txt");
if(infile.fail())
{
cout << " Error " << endl;
}
int numb_char=0;
char letter;
while(!infile.eof())
{
infile.get(letter);
cout << letter;
numb_char++;
}
cout << " the number of words is :" << numb_char << endl;
infile.close();
return 0;