//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 <fstream>#include <iomanip>#include <iostream>#include <string> //probly don't need it#include <vector>#include <stack>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 " <<fn<< " couldn't be opened. \n"; }};void stringreverser(ifstream& ifn, ofstream& ofn){ std::stack< char, std::vector<char> > 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<<input.top(); input.pop(); } if (ifn.eof()){break;} }}/** everything from here down should be damn easy for anyone who's had a year of c++ **/int main(int argc, char* argv[]){ try { char inputfilename[255], outputfilename[255]; switch (argc) { case 1: cout << "USAGE: progname inputfile outputfile \n"; cout << "Need an input file. \n"; cin >> 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); }}