Sunday, 13 March 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

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment