#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream file("Programming.txt");
if(file.is_open())
{
string line;
int wordcount = 0;
while(getline(file, line))
{
stringstream ss(line);
string word;
while (getline(ss >> ws, word, ','))
{
if (word == "Ball")
wordcount++;
}
}
file.close();
cout << "Ball occurred " << wordcount << " times";
}
else
{
cerr << "File is closed!";
}
}
Ball, Ball, Cat, Dog, Ball,