Skip to content

Instantly share code, notes, and snippets.

@grogy
Created March 14, 2013 21:19
Show Gist options
  • Save grogy/5165381 to your computer and use it in GitHub Desktop.
Save grogy/5165381 to your computer and use it in GitHub Desktop.
C++ - check file for open.
/**
* Check file for read / write
* (isForOpen) ? "read" : "write"
*/
bool checkFile(const char * fileName, bool isOnlyRead)
{
if (isOnlyRead) {
ifstream inFile;
inFile.open(fileName, ios::in);
if (inFile.is_open()) {
inFile.close();
return true;
}
return false;
} else {
ofstream inFile;
inFile.open(fileName, ios::out);
if (inFile.is_open()) {
inFile.close();
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment