This is the opposite of How to convert a vector<char*> to a vector<string>/string question.
I have some legacy routine which works with vector<char*>
so I need to transform my vector<string>
.
Here is what I come out with:
std::vector<char*> charVec(strVec.size(),nullptr);
for (int i=0; i<strVec.size();i++) {
charVec[i]= new char(strVec[i].size()+1);
charVec[i][strVec[i].copy(charVec[i], strVec[i].size())] = '\0';
}
Is this correct?
Is there a better way to implement it?
p.s. of course at the end I have:
for (int i=0; i<strVec.size();i++) {
delete charVec[i];
}