Hi. I am having a problem. What I am trying to do is input a text file. From the file I want to find out how many words are on there and then I want to know how many characters are in the text file for each letter. For example :the dog.
That has 1 t, 1 h, 1 e, 1 d, 1 o, 1 g, 1 .
Then i need to output the text from the file to the screen and then output how many words and each of the letters in alphabetical order.
How can i do that? So far all I have been able to do is count how many words but I cannot find a way of how to count the characters or anything. Can anyone help?
This is my code:
Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string word; int count=0; ifstream fin; fin.open("input.txt"); if (fin.fail()) { cout<<"Couldn't read file. \n"; cin.get(); return 0; } while(!fin.eof()) { fin>>word; cout<<word<<" "; ++count; } cout<<"\nThere are: "<<count<<" words"; fin.close(); cout<<"\nPress enter to exit"; cin.get(); return 0; }



LinkBack URL
About LinkBacks



