The accepted answers in
- Convert char** (c) to vector<string> (c++)
- copying c array of strings into vector of std::string
- converting an array of null terminated const char* strings to a std::vector< std::string >
populate the vector at the same time as declaring it:
vector<string> vec(cArray, cArray + cArrayLength)
But what if I need to do it separately because I need to expand the scope of the vector, e.g. in
vector<string> vec;
if (some_condition)
// copy a char** to vec
else
// copy another char** to vec
do_something(vec);
How do I copy the arrays then?