Advertisement
KeeganT

Ass73

Oct 23rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string text;
  9.     int charCount=0, lineCount=0, wordCount=0, num=0;
  10.     ifstream file("Ass73.txt");
  11.     while(getline(file,text))
  12.     {
  13.         cout<<text<<endl;
  14.         lineCount++;
  15.         wordCount+=1; //first word of the line
  16.         for(int c=0;c<text.length();c++)if(text[c]==' '&&text[c+1]!=' '&&text[c+1]!=NULL)wordCount+=1;
  17.         charCount+=text.length();
  18.     }
  19.     cout<<"\nNumber of characters: "<<charCount<<endl;
  20.     cout<<"Number of words: "<<wordCount<<endl;
  21.     cout<<"Number of lines: "<<lineCount;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement