title: How to convert a vector<string> to null terminated char **?
body: <p>I'm trying to convert a <code>std::vector&lt;std::string&gt;</code> to a NULL terminated array of C-style strings (<code>char *</code>). Is it possible without copying with <code>new</code>/<code>malloc</code>?</p>
  
  <p>Basically, I want to convert vec back into the EXACT SAME thing as arr without new/malloc.</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  
  void print(const char **strs)
  {
     const char **ptr = strs;
     while(*ptr) {
        printf("%s ", *ptr);
        ++ptr;
     }
  }
  
  void print(std::vector&lt;std::string&gt; &amp;strs) {
     for(auto iter = strs.begin(); iter != strs.end(); ++iter) {
        printf("%s ", iter-&gt;c_str());
     }
  }
  
  void main()
  {
     const char *arr[] = { "a", "b", "c", "d", "e", "f", NULL };
  
     vector&lt;string&gt; vec;
  
     const char **str = arr;
     while(*str) {
        vec.push_back(*str);
        ++str;
     }
     vec.push_back((char *) NULL); //Doesn't work
  
     //print(vec);
     print((const char **) &amp;vec[0]);
  }
  </code></pre>