#include <QtCore/QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
void parseCommandLine(int argc, char* argv[], string &input, string &output);
void copyFile(istream &in, ostream &out);
void getFile(char* title, char *title2, string &input, string &output);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
string infile;
string outfile;
getFile("Enter the name of the input file", "Enter the name of the output file", infile, outfile);
parseCommandLine(argc, argv, infile, outfile);
exit(0);
copyFile(infile, outfile);
return a.exec();
}
void getFile(char* title, char title2, string infile, string outfile)
{
cout << title;
cin.getline(infile);
cout << title;
cin.getline(outfile);
}
void parseCommandLine(int argc, char* argv[], string& input, string& output)
{
cout<<input;
cout<<output;
if( argc < 2)
{
cout<<"Useage: argvArgc [/o=filename] [/i=filename]"<<endl;
exit(1);
}
for(int i = 1; i < argc; i++)
{
if(argv[i][0] != '/')
{
cout<<"Illegal operand. Program terminating"<<endl;
exit(1);
}
switch(toupper(argv[i][1]))
{
case 'I' : input.open(argv[i][3]);
if(input.fail())
{
input.close();
input.clear();
cout<<"Input file does not exist!"<<endl;
exit(1);
}
in = input;
break;
case 'O' : output.open(argv[i][3]);
out = output;
break;
default : cout<<"Illegal option. Program terminating"<<endl;
exit(0);
}
}
}
void copyFile(istream &in, ostream &out)
{
char data;
while(in>>data)
out<<data;
if(in != cin)
in.close();
if(out != cout)
out.close();
}
|