//Write a program that takes a file for input (hard coded or user inputted, doesn't matter) //and saves a new file with the text on each line reversed. #include #include #include #include //probly don't need it #include #include using namespace std; struct CommandLineException { CommandLineException(int max,int actual){ cout << endl << "Too many files, MORON! \n"; cout << "Only " << max << " arguments are permitted. \n"; cout << actual << " arguments were entered. \n"; } }; struct FileException { FileException(char* fn){ cout << "\n file " < > input; // never used a vector or used the built in stack class before, didn't feel like making my own stack //probly could do without it all together char v; for(;;){ // don't try this at home kids. while(ifn.get(v)){ // try learning this one from scratch, HINT: get() returns an int input.push(v); if(v == '\n'){break;} //if the last line of the inputfile dosn't have a \n then it //and the line before it will be the same line in the outputfile } while(!input.empty()){ ofn<> inputfilename; cout << "Need an outputfile. \n"; cin >> outputfilename; break; case 2: strcpy(inputfilename,argv[1]); cout << "Need an outputfile. "; cin >> outputfilename; break; case 3: strcpy(inputfilename,argv[1]); strcpy(outputfilename,argv[2]); break; default: throw CommandLineException(2,argc-1); break; } ifstream ifn(inputfilename); if (!ifn) throw FileException(inputfilename); ofstream ofn(outputfilename); if (!ofn) throw FileException(outputfilename); stringreverser(ifn, ofn); ofn.close(); ifn.close(); } catch(...) { cout << endl << "Game Over" << endl; exit(EXIT_FAILURE); } }