I\'m processing a record-based text file: so I\'m looking for a starting string which constitutes the start of a record: there is no end-of-record marker, so I use the start
I think this is because message is defined inside the loop. At the end of the loop iteration "message" goes out of scope. Defining "message" outside of the loop stops the variable from going out of scope at the end of each loop iteration. So I think you have the right answer.
You could output the value of message at the beginning of each loop iteration to test whether my suggestion is correct.