0

Hello,
I'm building a cp like program and here is the code of the file copy, i'm in the beginning, i'm going to put the error messages when i be in some good state of the program:

#include <iostream>
#include <fstream>
using namespace std;

int main( int argc, char* argv[] )
{  
    char* inputFile;
    char* outputFile;
    inputFile = argv[ 1 ];
    outputFile = argv[ 2 ];
   
    ofstream(outputFile) << ifstream(inputFile).rdbuf();
  return 0;
}

But how i can do a code that the program finds if the file is in the directory that the terminal is and copy it to the output location, remember that i'm using Linux.

Thanks,
Nathan Paulino Campos

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Nathan Campos
0
int main( int argc, char* argv[] )
{  
    char* inputFile;
    char* outputFile;
    inputFile = argv[ 1 ];
    outputFile = argv[ 2 ];
    ifstream in(inputFile);
    if( in.is_open() )
    {
        ofstream out(outputFile);
        out << in.rdbuf();
    }
    //ofstream(outputFile) << ifstream(inputFile).rdbuf();
  return 0;
}
Votes + Comments
Thanks very much, you're a very good man!
0

Thanks very very much, now i can go ahead with my simple project, thanks for your help, you are a very good man, because you help many people!
Thanks!
+1 Of Reputation!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.