I have started working on the file using C ++ for the first time and I would like to write a correct program that Allows me to
- Open the path giving file;
- If it fails to open (showing what error does not make any difference), ask a new route;
- Working on the file;
- Close the file;
The only point I can not do is second I have already tried some way:
do {cout & lt; & Lt; "Path:"; Cin & gt; & Gt; Path; F. Open (path, ios :: in); } While (f.fail ());
But if I write the path of an uneven file and then the path to the file that I want to open, the program constantly asks me for a new route and never closes.
PS = Will it be different if I use a new file using ios :: out (for example: a file name / extension containing invalid characters) Want to use the situation to prevent errors in creating?
Clear flags if its failed
f.open (path, IOS: in); Whereas (f.fail ()) {f.clear (); Std :: cout & lt; & Lt; "Wrong file path, re-enter"; Std :: CIN & gt; & Gt; Path; F. Open (path, ios :: in); }
Comments
Post a Comment