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

后端 未结 4 1405
一生所求
一生所求 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条回答
  •  误落风尘
    2021-01-12 13:15

    std::cin is of type std::basic_istream which inherits from std::basic_ios, which has an operator : std::basic_ios::operator bool which is called when used in if statement.

提交回复
热议问题