#include <iostream>
#include <string>
using namespace std;

int count_char(const string& str, char c)
{
    int count = 0;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == c) { count++; }
    }
    return count;
}

int main()
{
    string quote = "I hope life isn't a big joke,";
    quote += "because I don't get it.";
    quote += "\n-- Deep Thoughts, by Jack Handey";

    cout << quote << endl;
    cout << "Number of spaces in quote: ";
    cout << count_char(quote, ' ') << endl;
    cout << "Number of a's in quote: ";
    cout << count_char(quote, 'a') << endl;
    cout << "Number of b's in quote: ";
    cout << count_char(quote, 'b') << endl;

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: