I have this code that works good, but I am wondering if I can use !input.eof() function in this case instead of while(input)..
The data in the text file is:
Ahmed 1500
Mohamed 600
Ali 3000
What do you expect to gain? Actually, input can fail for other reasons than eof, so testing the stream for failure (as you are doing through istream's operator bool overload) is usual best. Although we often test the input function's return value itself: