Skip to content
Advertisement

Copy a file from one directory to another in C++

I am writing a C++ program to copy one file from one directory to another. I don’t want to use C++ 17 features. I have already implemented this in the following code.

JavaScript

I am on Linux and I want to use the OS cp command to do this. I have written this code.

JavaScript

The error is: cp: source: No such file or directory, How do I do this using system()?

Advertisement

Answer

Change this:

JavaScript

To this:

JavaScript

And BTW, you should either return from inside the if(argc != 3) statement, or do the rest of the code inside an else statement.

Lastly, function int main(int argc, char *argv[]) requires that you return an int value.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement