getline can fail if you already reached the last line of the file. But you don't check the state of the stream until after you print the line.
The best way to solve this would be to put getline as the condition of the loop itself. This will stop the loop as soon as getline fails, and eliminates the need for redundant safety checks.
1 2 3 4
while (getline(inFile, line))
{
cout << line << "\n";
}
See how I formatted my code? Please do the same to your code, you can edit your post, highlight your code, and press the "<>" button under Format options.