So I have a coin flipping program that ouputs all results to a txt file. I was wondering how would i search the results so that I could pick out things like how many times a specific result was repeated in a row. For example if the results were
Heads
Tails
Heads
Tails
Tails
Tails

Then the search would tell me that there were three tails in a row.

I would read from the text file and store the contents of the .txt file into some sort of a container; probably a <string> class object.

Once you have your string container(s) populated, loop through the string(s) and keep two counter variables that will increment any time a string == "Heads" or string == "Tails".

ifstream infile;
string results[100];

int heads=0, tails=0;


int i=0;
while(infile >> results[i])
{
     if(results[i] == "Heads")
     {
          heads++;
     }
   
     else
     {
          tails++;
     }
   
     i++;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.