I often use the execv()
function in C++, but if some of the arguments are in C++ strings, it annoys me that I cannot do this:
const char *args[4];
args[0] = "/usr/bin/whatever";
args[1] = filename.c_str();
args[2] = someparameter.c_str();
args[3] = 0;
execv(args[0], args);
This doesn't compile because execv()
takes char *const argv[]
which is not compatible with const char *
, so I have to copy my std::string
s to character arrays using strdup()
, which is a pain.
Does anyone know the reason for this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…