I have a text file that I am supposed to open, scan, and count the amount of times a particular word or string occurs in the text file ("#email" to be exact). I have been able to count the number of words that occurs in the whole text file but not count the number of times a particular word or string occurs. Can anyone give me any advice?
int count = 0;
std::string word;
std::string strg1("#email");
std::ifstream fin;
fin.open(filename + "-inbox.txt", std::ios::in);
while (fin >> word)
{
if (word == strg1)
{
count++;
}
}
fin.close();
return count;