This is my first post on a problem thats driving me slowly mad so here goes. What im trying to do is to write a method that takes 2 char parameters called filenameIn and filenameOut, so that i can read from an input file and copy the contents into an output file. The code i have written so far compiles and links fine but doesnt do anything-i have programmed before but only in java so this problem is one that i want to try and solve as its holding me up finishing the program. This is the code i have so far:
Code:
#include <iostream>
#include "textfilecopy.h"
using namespace std;
/*
* Partially completed program
* The program should copy a text file.
*
*/
int main(int argc, char **argv) {
if (argc !=3) {
cerr << "Usage: " << argv[0] << " <input filename> <output filename>" << endl;
int keypress; cin >> keypress;
return -1;
}
textfilecopy tfc;
int keypress; cin >> keypress;
}
That is my main.cpp, then there's textfilecopy.h:
Code:
#pragma once
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
class textfilecopy
{
public:
textfilecopy();
~textfilecopy();
Copy ( char* filenameIn, char* filenameOut)
{
ifstream infile ("C:\\Documents and Settings\\Paul McKenzie\\Programming Work\\Parser\\Debug\\input.txt");
if (!infile) {
cerr << "Can't open input file " << filenameIn << endl;
exit(1);
}
ofstream outfile("C:\\Documents and Settings\\Paul McKenzie\\Programming Work\\Parser\\Debug\\output.txt");
if (!outfile) {
cerr << "Can't create output file " << filenameOut << endl;
exit(1);
}
string s;
while (infile >> s) {
outfile << s << endl;
}
infile.close();
outfile.close();
}
};
and finally textfilecopy.cpp
Code:
#include ".\textfilecopy.h"
textfilecopy::textfilecopy()
{
}
textfilecopy::~textfilecopy()
{
}
If anyone could help me out id be so grateful, as i say im new to C++ so it wouldnt suprise me if i missed something basic, or put things in the wrong place lol
Thanks a lot,
Paul