In the beginning I wrote something like this
char* argv[] = { "ls", "-al", ..., (char*)NULL };
execvp("ls", argv);
However, GCC detected this warning: "C ++ forbids converting a string constant to char*
."
Then I changed the code to
const char* argv[] = { "ls", "-al", ..., (char*)NULL };
execvp("ls", argv);
As a result, GCC discovered this error: "Invalid conversion from const char**
to char* const*
."
Then I changed the code to
const char* argv[] = { "ls", "-al", ..., (char*)NULL };
execvp("ls", (char* const*)argv);
It finally works and compiled without any warnings and errors, but I think it is a little cumbersome and I cannot find anyone to write something like this on the Internet.
Is there a better way to use execvp
in C ++?
source
share