I have a legacy function that has an input parameter of type const char\* array

```
myfunc(const char* names[]);

```

I have a set `std::set<std::string> mynames;`. The set has already been populated.
I have to pass `mynames` to `myfunc`

Using range based loop, I have

```
const char* names[];
int i = 0;
for (const auto &name : mynames)
{
    //allocate memory to names here
    names[i] = name.c_str();
    ++i;
}

//call myfunc
myfunc(names);

```

Is there a better way to do this?