Thursday 15 July 2010

c++ - Trying again and again to open a file while giving wrong path -



c++ - Trying again and again to open a file while giving wrong path -

i've started working on file using c++ first time , write right programme allows me to:

open file giving path; if fails open (showing error doesn't matter), inquire new path; working on file; close file;

the point can't sec one. i've tryed somethink like:

do{ cout<<"path: ";cin>>path; f.open(path, ios::in); }while(f.fail());

but if write path of inexisting file , path of file want open, programme continously inquire me new path , never stops.

p.s. = different if want utilize status prevent errors while creating new file using ios::out (for example: file name/extension contains illegal characters)?

clear flags if unsuccessful

f.open( path, ios::in ) ; while( f.fail() ) { f.clear(); std::cout<<"incorrect file path, re-enter "; std::cin>>path; f.open( path, ios::in ) ; }

c++ file fstream

No comments:

Post a Comment