How does cin evaluate to true when inside an if statement?

后端 未结 4 1362
一生所求
一生所求 2021-01-12 12:18

I thought that:

if (true) 
{execute this statement}

So how does if (std::cin >> X) execute as true when there is nothing

4条回答
  •  -上瘾入骨i
    2021-01-12 13:04

    if(x) is equivalent to if(bool(x))

    in this case bool(x) calls std::istream::operator bool(x)

    this will return:

    true if none of failbit or badbit is set.

    false otherwise.

提交回复
热议问题