How to pass a dymamic array of strings pointers from C++ to a C function
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/7048888/stdvectorstdstring-to-char-array">std::vector&lt;std::string&gt; to char* array</a>  </p>
</blockquote>



<p>I have to call a c function that accepts an array of string pointers. Example</p>

<pre><code>void cFunction(char* cities[], int count)
 {
   for(int i = 0; i &lt; count; ++i )
   {
    printf("%s\n", cities[i]);
   }
 }
</code></pre>

<p>Assume that function is in some third party libabry; it cannot be changed<br>
I can declare a static array and call the function like this<br></p>

<pre><code>char* placesA[] = {"Teakettle Junction", "Assawoman Bay", "Land O' Lakes", "Ion", "Rabbit Hask" };
cFunction(placesA, 5);
</code></pre>

<p><br>
That works. But my data is dynamic i.e. the size of the array changes many times at runtime<br>
So I tried this<br></p>

<pre><code>std::vector&lt;std::string&gt; placesB(placesA, placesA + 5);
cFunction(&amp;placesB[0], 5); // this won't work because std::string != char*[]
</code></pre>

<p><br>
Tried this <br></p>

<pre><code>std::vector&lt;char*&gt; placesC; 
cFunction(&amp;placesC[0], 5);
</code></pre>

<p>I find <code>placesC</code> awkward to populate at the sametime avoid memory leaks<br> I am looking for a solution that is both efficient ( as little string copying as possible and preferably uses STL and or Boost )</p>
