You could use a circular buffer.
- Open the file
- Read a line
- Read address and discart it
- Read first value and put it into the buffer
- Read next value, and throw last value of the buffer (std::list could be good for that)
- Check if buffer contains the pattern
- Loop through 5 up to the end of the line
- Loop through 2 up to the end of the file