I was looking at some questions on here that shows you how to read from a txt file, and then assign anything in it to separate variables. The answer used a while loop that looked like this...
ifstream file(“file.txt”);
int var1;
int var2;
int var3;
while (file >> var1 >> var2 >> var3)
{
/* do something with name, var1 etc. */
cout << var1 << var2 << var3 << “\n”;
}
My question is, what is happening in that while loop that allows it assign those variables the right value? I know that it works, because I used it, but I just don't understand how it works.
Here's the link I was looking at, just in case anybody wanted to also look at it. C++: Read from text file and separate into variable
Thanks!