This works because of two properties of istream objects:
- istreams return themselves after each extraction (the
>>
operator) to allow chaining multiple extractions (a >> b >> c
)
- istreams return their status (as though
.good()
were called) when they're cast/converted to bool, via overloading bool operator !()
Basically the code you wrote is a short-hand version of:
if ( ((((ibuf >> zork) >> ia) >> Comma) >> ib).good() ) {
}
Once all the extractions have occured, you're left with if (ibuf)
which is implicitly like writing if ((bool)ibuf)
, which checks ibuf.good()
.
There is no way to get the number of characters extracted over a series of chained extractions, but you can find the number of characters extracted during the last operation with the function gcount. However, it only works for certain format-ignoring functions like get
and getline
, and not the extraction operator.