converting an array of null terminated const char* strings to a std::vector< std::string >
Something like this?:
vector< string > ret( array, array + count );
Try this:
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
int main(int argc,char* argv[])
{
// Put it into a vector
std::vector<std::string> data(argv, argv + argc);
// Print the vector to std::cout
std::copy(data.begin(), data.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
}
Assuming that the signature of your function is inadvertently wrong, do you mean something like this?
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
std::vector<std::string> Convert(int count, const char **arr)
{
std::vector<std::string> vec;
vec.reserve(count);
std::copy(arr, arr+count, std::back_inserter(vec));
return vec;
}
int main()
{
const char *arr[3] = {"Blah", "Wibble", "Shrug"};
std::vector<std::string> vec = Convert(3, arr);
return 0;
}