I came upon this syntax
for (string st; getline(is, st, ' '); v.push_back(st)); ^ ^ ^ initialization condition, increment ???
How does the v.push_back(st)
work as an increment when that's being covered by getline(is, st, ' ')
?
That's equivalent to:
for (string st; getline(is, st, ' '); ) v.push_back(st);
or:
{ string st; while (getline(is, st, ' ')) v.push_back(st); }
The fact is that the increment statement is executed at the end of the body of the loop every time the condition is fulfilled. So, you can see it as the very last instruction of the body.
Sometimes, you may leave the increment statement empty; in this case, you put the only instruction of the body in place of the increment statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With