Implicit cast to bool of basic_istream/ifstream/ofstream doesn't work in Visual Studio 2013

后端 未结 3 1153
小鲜肉
小鲜肉 2021-01-14 18:26

The code below compiles in VS 2012 but not in VS 2013

std::ofstream stm;
if(stm != NULL)
{
}

In VS 2013 you get this compilation error:

3条回答
  •  一向
    一向 (楼主)
    2021-01-14 18:51

    The operator is defined in section 27.5.5 Class template basic_ios.

    27.5.5.1 Overview

    explicit operator bool() const;

    And then

    27.5.5.4 basic_ios flags functions

    explicit operator bool() const;

    Returns: !fail().

提交回复
热议问题