First semester C++ assignment and this is the one thing I'm having trouble with in it:
Basically there's this txt file that has three numbers on each line of it - the loop reads those into three variables and uses them to create an object and process with it. We had to do this using three different loop techniques. The first two were done using a counter based for loop and a sentinel value based while loop and were straight forward for me.
The last one though says "Write an end of file loop that reads an integer from fin into x in the conditional expression." (fin is the ifstream object)
Does something like this work?
while (fin >> x && !fin.eof())
{
rest of loop stuff
}
This just seems really odd to me to have something reading into a variable inside a loop's conditional expression. Wouldn't it make more sense to do something like this?
while (!fin.eof())
{
fin >> x;
rest of loop stuff
}
Thanks, appreciate any guidance!