How does the “return value” of operator >> of istream class work?

后端 未结 2 1368
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 20:57

I tried to understand the statement:

    int main() {
        fstream inf( \"ex.txt\", ios::in );
        char c;
        while( inf >> c ) {
                  


        
2条回答
  •  时光取名叫无心
    2021-01-20 21:05

    What does ( inf >> c ) return in the while loop above?

    void*. The loop test resolves to while (inf.operator void*() != NULL).

    How does a reference can be evaluated as true or false?

    But supporting conversion to bool or something convertible to bool.

    How does the internal implementation of istream actually work?

    It just returns a reference to itself (return *this) so it can support chaining.

提交回复
热议问题