Up until C++ 11 NULL
represented an empty pointer. ifstream
supported comparison against NULL
so the code worked.
NULL
is no longer considered the correct approach for checking as it is really just a preprocessor value set to integer 0 which means the language had to allow pointers to work with arbitrary ints (which can cause issues). The language added the nullptr
keyword to replace it and this is the recommended value going forward. With that change ifstream
no longer supports the comparison but instead supports conversion to boolean. Hence you just need to change your code a little.
if (!inFile)
{
//Error
}