Please help... any suggestions? I'm trying to make my program robust by checking for errors using member function .is_open()
but it just doesn't seem to want to work today for some reason.
void promptfiles(string & infile, string & outfile)
{
do{
cout << "Which file do you want to encrypt? " << endl;
cin >> infile;
cout << endl << "Which file will you be saving it to? (caution may overwrite files if not careful) " << endl;
cin >> outfile;
}while(!check_files(infile, outfile));
}
Because opening a file for output creates an empty file if one doesn't exist. std::ofstream::is_open() will only return false if the file couldn't be created (e.g. because the file system is full or read-only).
EDIT: Some compilers let you pass a flag to the constructor or to open() that won't create an empty file, but this isn't standard.