I created this function to read line entries from a text file. I created a for loop using the “stuFile” variable to act as a bool data type so that the loop would execute until there were no more lines to read. The for loop also increments the “i” variable so that I can keep count of how many entries there are. Everything works fine in the function as far as reading from the file goes . The issue comes when the output to the console is displayed, there is always and extra number for example:
1) Tommy 1245
2) Jake 2354
3) Kate 8546
4)
There are only 3 entries in the file so I’m not sure why I’m getting this extra number can anyone help?
You get the number 4 printed, because the cout prints it before it finds out that entry is empty, meaning end of file reached. Here is your list() routine, made into a small program. I had to add a score variable to put the numbers into. I created the 'Students.txt', and this program printed all three lines, then stopped.