ifstream - Getting the user to enter a file C++ -


" assignment prompt user enter filename path on disk. if file not exist in specified location, program should exit suitable error message" hi everyone, i'm having issue, able user enter file name this..

1.         cout<< "enter data file name wish open"; 2.         cin >>file; 3.         indata.open(file.c_str()); 4.         outdata.open(file.c_str()); 

the second part of question if file not exist, program should make error, how go doing so, file name txt.source, user enters lil.pol how make there error, or other words how make file name desired 1 computer accept?

what can try open file , if fails open issue message through std::cerr this:

std::ifstream indata(file.c_str());  if(!indata) // failed open {     std::cerr << "error: not open file: " << file << std::endl;     return 1; // error code }  // use indata here (its open) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -