Find Frequency of Characters of a String Object

Description:

Write a simple C++ program to find the number of occurances of a character in a given string. Test Case 1 Input (stdin) balaraja a Expected Output 4 Test Case 2 Input (stdin) rajivkumar r Expected Output 2

Program :

#include <iostream>

using namespace std;

int main()

{

    string str ;cin>>str;

    char checkCharacter ;cin>>checkCharacter;

    int count = 0;

    for (int i = 0; i < str.size(); i++)

    {

        if (str[i] == checkCharacter)

        {

            ++ count;

        }

    }

    cout << count;

    return 0;

}