Reading a Specific File from a C++ code

Hi, I have a .txt file containing information about 1000 events; each event lists 10-15 hit information. This number is not fixed. The format is given below:
=================================================================
begin of event: 45

end of ...
==================
===================================================================

I need to pick up only the last line of each event and write them down in a separate .txt file. Thus, the same task to do for 1000 times. The problem is that here words are mixed up with numbers and it is difficult to pick the choice up. Please see where I got stuck:

This will be the skeleton of the code. But I fear I cannot implement the correct algorithm in the "?".. The algorithm will be following:

when the word "begin of event" is followed by an int, the lines will be written without being appended; that is, the former line will be overwritten. When the word "end of event" is encountered, the loop for next "begin of event" will start.

Can anyone please say if the algorithm is correct and if it is, how to impliment that in the code? Any help will be appreciated.

If you were to look at the list of hits on a piece of paper, how would you find the last one for each event? Yes, you would find the words "end of event" and look at the last non-blank line above that.

The algorithm should do exactly the same thing -- just look for the words "end of event" and then print the information on the last non-blank line. This will, of course, require you to remember the last non-blank line read before the line starting with the words "end of event".

Keep in mind that there is no point in parsing information about the hit until you have the line containing that information.