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

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;
}
commented: Thanks very much, you're a very good man! +1

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.