   c++ ifstream, cannot create a file.
  Hi again. I'm trying to create a file within a function like:fstream datafile;if (fileexists = checkfileexists(filename_)) cout << "Loading file " << filename_ << endl;else cout << "Creating file " << filename_ << endl;datafile.open(filename_.c_str(), ios::in | ios::app);if (!datafile.is_open()) {if (fileexists) {cout << "Could not load file. Please check the file " << filename_ << ".\n";return -3;} else {cout << "Could not create file. Please check disk space.\n";return -4;}}but the file can't open. After tracing a bit with the debugger I found out it can't find a valid state to set the file. Does anyone have any clue or have had a similar case? In checkfileexists I open the file to see if it exists and close it again. I tried taking out the checkfileexists function but still the file can't be created or opened.EDIT: Making a rdstate check I get a failbit flag. I think it means a non fatal I/O error.   
  Ouf! Finally got it. It has to do with the standard and how the function should be called. It needs to be different for creating a file and different for loading a file. So I solved with:fstream datafile;if (fileexists = checkfileexists(filename_)) {cout << "Loading file " << filename_ << endl;datafile.open(filename_.c_str(), ios::in);} else {cout << "Creating file " << filename_ << endl;datafile.open(filename_.c_str(), ios::in | ios::out | ios::trunc);}