Zobacz poniższy przykład:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string input, last, instruction;
int counter {1} , max_counter {0} , line {0}, start_line {0};
ifstream file {"instrukcje.txt"};
while( file >> input )
{
if( input.size()>1 )
{
++line;
if( last == input )
{
++counter;
}
else
{
if( last != "" )
{
if( max_counter < counter )
{
instruction = last;
max_counter = counter;
start_line = line - counter;
}
counter = 1;
}
}
last = input;
}
}
cout << "Instruction " << instruction << " started at line " << start_line << " and counts " << max_counter << endl;
}