C++ Program to Count Occurrence of Word using File Handling

By | January 5, 2017

Count Occurrence of Word using File Handling


Write a C++ Program to Count Occurrence of Word using File Handling. Here’s simple C++ Program to Count Occurrence of Word using File Handling in C++ Programming Language.


This C++ program will read  a word from user and then count its total occurrence in a text file “file4.txt”. Make sure you have already create this text file and have some text in it. Place this file in the same directory where your program source file is present.

Below is the source code for C++ Program to Count Occurrence of Word using File Handling which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



Above is the source code for C++ Program to Count Occurrence of Word using File Handling which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

One thought on “C++ Program to Count Occurrence of Word using File Handling

  1. caprisun77

    Hey there, great piece of code. However when i try applying it to a file of my own that i want it to read from it fails and comes up with the (11db) error. Can you help me with this???

    #include
    #include
    #include
    #include
    using namespace std;

    int main()
    {

    ifstream fin(“/Users/williamthatcher/Desktop/TwitterFeed/sampleTweets.csv”); //opening text file

    int count=0;
    char ch[20],c[20];

    cout <> c;

    while(fin)
    {
    fin>>ch;
    if(strcmp(ch,c)==0)
    count++;
    }

    cout<<"Occurrence of word" << c << " = " << count << endl;
    fin.close(); //closing file

    return 0;

    }

    Reply

Leave a Reply