Thread: Read/Write Method

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    13

    Read/Write Method

    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
    Last edited by bigpmc; 10-18-2004 at 09:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 07:50 PM
  2. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 05:17 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-08-2008, 12:30 AM
  4. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM
  5. Replies: 2
    Last Post: 01-22-2008, 04:22 PM