Skip to content

Instantly share code, notes, and snippets.

@leandrobmarinho
Created March 6, 2019 21:20
Show Gist options
  • Save leandrobmarinho/847b7498bc03f54c44c8eff6b5dc0f20 to your computer and use it in GitHub Desktop.
Save leandrobmarinho/847b7498bc03f54c44c8eff6b5dc0f20 to your computer and use it in GitHub Desktop.
Here is a simple program in C++ to verify if a file exists using ifstream.
#include <iostream>
#include <fstream>
using namespace std;
bool fexists(const char *filename)
{
ifstream ifile(filename);
return ifile;
}
int main () {
cout << fexists("filename") << endl;
return 0;
}
@PsionixSoftworks
Copy link

Wrong. "ifile" is of type std::ifstream. The return type bool is incompatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment