I've just started working on file using C++ for the first time and I would like to write a correct program which allows me to:
- Open the file giving the path;
- If it fails to open (showing which error is doesn't matter), ask a new path;
- Working on the file;
- Close the file;
The only point I can't do is the second one. I've already tryed somethink like:
do{
cout<<"Path: ";cin>>path;
f.open(path, ios::in);
}while(f.fail());
but if I write the path of an inexisting file and then a path of the file I want to open, the program continously ask me a new path and never stops.
P.S. = Will it be different if I want to use that condition to prevent errors while creating a new file using ios::out (for example: a file name/extension which contains illegal characters)?