This is what I have so far... The point of this program is to display the number of words in a file, and also get the number of letters in the number of words of that same file.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int numberOfWords = 0, i = 0;
char letters = 0;
string line;
ifstream myFile;
myFile.open("text.txt");
//I got this to work, it displays the number of words in the file
if (myFile.is_open())
{
while (!myFile.eof())
{
myFile >> line;
i++;
}
numberOfWords = i;
//this is where I'm having trouble. I can't get this code to work for it to display the number of letters in the file.
while (!myFile.eof())
{
//cout << line << endl;
letters = line.length();
letters++;
}
}
myFile.close();
cout << "There are " << numberOfWords << " words in the textfile\n"
<< "There are " << letters << " letters in those " << numberOfWords << " words\n";
cin.get();
return 0;
}