in reply to Scanning a file for a match, printing different part of the line when found.

I found this code to scan a file and print each occurrence of a string.

That only works correctly if the "search string" is not at the end of the file, otherwise it prints one less than the correct number.

And even though you are using the "getline" method you are not actually reading "lines" because you are re-defining the Input Record Separator from its normal value of "\n" to something else so you are actually reading "records".

  • Comment on Re: Scanning a file for a match, printing different part of the line when found.