Q:

C++ Program To Count Number Of Characters In a File Using File Handling

0

Explanation:- 

So basically we have to take an input from a filename with the extension .c/cpp/.java/.txt and many other and hit the enter after hitting enter program will return the total character in a file. In other words, we can say that this is a program for counting a total number of character in a file.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
char FileName[] = "example.txt";
int main ()
{
string line;
ifstream inMyStream (FileName);
int c;

if (inMyStream.is_open())
{

     while(  getline (inMyStream, line))
  {

             cout<<line<<endl;
             c += line.length();
           
     }
     cout<<"\n\n"<<"Total Character In File "<<c<<endl<<endl;
    }
    inMyStream.close();

system("pause");
   return 0;
}

 

Input:

 

Output:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program to List and Display Files in Current D... >>
<< C++ Program For Find The Sum of Integers In a File...