13/03/2016

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

Problem:- C++ Program To Count Number Of Characters In a File Using File Handling or c++ program to count number of characters words and lines in a file or c++ program to count number of characters in a text file or count words in text file c++ or c++ program to count number of characters words and lines in a file or c++ program to count number of spaces in a file or c++ program to count number of characters in a word or c++ count letters in text file or write a c++ program to count the number of digits present in a text file or count number of lines characters and words in a file


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.


Solution:-

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

using namespace std;
char FileName[] = "example.txt";
//Ghanendra Yadav
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;
}

Output:-

Input:-

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


Output:-

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


You May Like This

1. C Program For Open A File (Or Open The Same Program Itself ) Itself Using File Handling

2. C++ Program To Merge Two File Into Third File Using File Handling

3. C++ Program For Copy One File To Another Using File Handling

4. C++ Program For School Management System ( SMS Project ) With Source Code

5. Hacker Rank Solution For Mini-Max Sum

6. Hacker Rank Solution For Birthday Cake Candles

7. C++ Program For Store Employee Information And Display Using Structure

8. C Program For Find A Grade Of Given Marks Using Switch Case

9. C Program For HEAP Sort In Ascending Order Also Show Complexity

10. C++ Program For Selection Sort Using Function
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: