I was think something like:
const char * res[cnt];
int i = 0;
for (auto mystring : strings) {
const char * str = mystring.c_str();
res[i++] = str;
}
//then pass res as const char **
But it occurred to me that 'str' is a local variable, the address stored in res could be invalid? What is the right way to do so?
stringsis, what its lifetime is, and what you are going to do withres. and whatcntisautoinstead ofauto &, so there may indeed be an issue.