Std :: ofstream == NULL will not compile for -std = gnu ++ 11, any workaround?

Consider the following code:

std::ostream file;
if( file == NULL ) std::cout << "Failed to open file" << std::endl;

It compiles fine when passing -std = gnu11 (default from GCC 5.2) or just using gcc code.cpp -o a.out.

It does not work with -std = gnu ++ 11 , though:

no match foroperator==’ (operand types are ‘std::ofstream {aka std::basic_ofstream<char>}’ andlong int’)`

What is the easiest workaround?

More details:

I need to use std = gnu ++ 11 to access definitions shared_ptr. In addition, some of my code is automatically generated, and changing the generator will be a reasonable effort - so I was wondering if anyone could come up with a simpler way to get rid of this "lack of compatibility".

+4
1

, - , , std::ios, ofstream , (!) operator void* ++ 11. ++ 11 explicit operator bool, , .

if (!file) std::cout << "Failed to open file" << std::endl;
+18

Source: https://habr.com/ru/post/1607494/


All Articles