My system is Ubuntu 20.04. Suppose I am in project
directory and this directory contains these folders/files: test
, hello.txt
. I wrote the following program:-
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]){
const char* command = "ls" + argv[1];
system(command);
return 0;
}
And then I will test
as first argument of the program while running it. I expected it will print all files and folders in test
folder. But it gave me an error.
Can someone tell me, what is the error and how to fix it?