I'm trying to understand how the following while loop works:
//...
ifstream inf(filename);
char command;
int value;
//...
while(inf >> command >> value)
{
if (command == 'i')
list.insert(value,listItr);
else
list.remove(value);
}
I read the answers to a similar question and understand how the while loop condition returns a bool. But I'm confused on how the command
and value
variables are assigned.
The file being read looks like this:
Has a series of 250,000 insertions in order from 1 to 250000
i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 i21 i22 i23 i24 i25...
I figured the while condition would succeed only when reading i1 i2 etc. However, the loop gets past the first line of the file. Does the condition return true as long as any characters are read, regardless if they were mapped to variables?