26. (8 pts) Finish, using a while loop, the code segment below so that the follo
ID: 3586952 • Letter: 2
Question
26. (8 pts) Finish, using a while loop, the code segment below so that the following actions are performed a) Prompt the user for the name of an input file and read it. b) Open the file c) While the file does not open successfully, print out a message stating as such, reset the input stream variable (code to do this is inFile.clear):) d) Repeat steps a,b,c until a file is successfully opened or the user enters ctrl-c. ifstream inFile; string filename; cout filename; inFile.open (filename. c str)) // rest of the code segment goes below this lineExplanation / Answer
while(1){ // implenting d , adding the loop unless it will get a new file
cout << "Enter the name of the iput file (or ctrl-c to exit):";
cin >> filename;
inFile.open(filename.c_str());
//implementing c
if(!inFile){ // checking whether inFile
cout<< reset the input stream variable << endl;
inFile.clear();
}
else
break;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.