c++ - Why is this loop not looping? -
i need this: open user-specified file input. prompt name of file, read string variable, echo print terminal , open it. if file not opened, come in loop prints out error message, resets input file stream variable (input_file_stream_var.clear(); input_file_stream_var name of input file stream variable), obtains new file name , tries open new file. loop continues until user enters valid file name or presses ctrl-c exit.
and here code have far cant loop process if file not opened.
#include <iostream> #include <fstream> #include <string> #include <sstream> #include <iomanip> using namespace std; int main() { // variables char test; string infname, outfname; fstream infile, outfile; { // propt , echo print input file cout << endl << "enter name of input file: "; cin >> infname; cout << infname << endl; infile.open(infname.c_str()); // test if file opened if(!infile) { cout << string(12,'*') << " file open error " << string(12,'*') << endl; cout << "==> input file failed open properly!!\n"; cout << "==> attempted open file: " << infname << endl; cout << "==> please seek again...\n"; cout << string(41,'*') << endl; infile.clear(); homecoming 1; } } while(!infile.is_open()); homecoming 0; }
the return 1
statement causing programme exit: returning main()
just don't that.
c++
No comments:
Post a Comment