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

后端 未结 3 1131
小鲜肉
小鲜肉 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:39

    If you have a lot of legacy code, you could probably add a custom operator!= (and operator==) function which takes the correct arguments:

    bool operator!=(std::basic_ios const& ios, const void* ptr);
    bool operator!=(const void* ptr, std::basic_ios const& ios);
    

提交回复
热议问题