I am trying to search for a word in a file, and each time it appears it increases the count by 1.
The file currently has multiple lines with the word Culture
in it. The program outputs 1 for each time it runs.
int main()
{
fstream plate("data.txt", ios::in | ios::out | ios::app);
int count = 0;
string search = "Culture";
string temp;
while(!plate.eof())
{
getline(plate, temp);
if(temp == search)
{count++;}
}
cout << count << endl;
return 0;
}
I don't see why it only outputs 1 every time