0

What is the purpose of the condition given in the while loop While(! Infile.eof())

Given below is the code segment of a file handling program. What is the purpose of the condition given in the while loop While(! Infile.eof()) { Infile>> name>>sal>>dept; Cout<< name<<"\ t"<< saal<<"\ t"<< dept<< endl; }

14th Dec 2019, 5:22 PM
Mohamed SalmanYousufxai
Mohamed SalmanYousufxai - avatar
2 Answers
+ 4
I'm not sure but since eof means end of file, so Infile.eof() will not return true until the end of the file is reached so it returns false everytime but the ! operator makes the condition true and the while loop continuously runs. So it prints the data from the file and when end of file is reached, the Infile.eof() returns true but the ! operator make the condition false and the loop breaks.
14th Dec 2019, 5:38 PM
Avinesh
Avinesh - avatar
+ 1
it means, if not at the end of file keep looping.
14th Dec 2019, 5:35 PM
Bahha┣
Bahha┣ - avatar