code error help

I'm getting this error when trying to compile does anyone know a solution?


420|error: cannot convert 'std::ifstream {aka std::basic_ifstream<char>}' to 'bool' in return|

1
2
3
4
5
 bool fexists(const char *filename)
{
  std::ifstream ifile(filename);
  return ifile;
}
C++11 and later require an explicit cast:

1
2
3
4
bool fexists( const std::string& filename )
{
    return static_cast<bool>( std::ifstream( filename ) );
}

Last edited on
Thank you for helping it worked
Topic archived. No new replies allowed.