I think you need in the while loop a conditional statement that compares the line you are getting from a file and a desired data( in your case is B345). Once you got that, print the next two lines and break the while loop.
while ( reading from a file )
temp variable = get line from the file;
if ( desired data == temp )
print the desired data and the next two lines;
I would suggest storing the data in a container when getting it from the file, then manipulating the information int the container you have chosen, once done you just simply over-write the file with the
to keep it simple you can use a vector you know that all the data is stored as 3s so when you get a match you simply over write the data for the next two elements with the new.
else you can have a class and use even a map if you know how to. lots of flexible ways to do it. just go with the one that is easier for you.