title: What is the best way to return a vector from a function in c++
body: <p>I have a function that returns an array like this:</p>
  
  <pre><code>vector&lt;string&gt; GetString()
  {
     vector&lt;string&gt; s;
     s.push_back("one");
     s.push_back("two");
     s.push_back("three");
     return s;
  }
  </code></pre>
  
  <p>and I'm calling it in this way:</p>
  
  <pre><code>   vector&lt;string&gt; mystrings=GetStrings();
  </code></pre>
  
  <p>I can implement it as follows too:</p>
  
  <pre><code>void GetString(vector&lt;string&gt; &amp; s)
  {
     s.push_back("one");
     s.push_back("two");
     s.push_back("three");
  }
  </code></pre>
  
  <p>and call it in this way:</p>
  
  <pre><code> vector&lt;string&gt; mystrings;
   GetStrings(mystrings);
  </code></pre>
  
  <p>Which one is better?</p>
  
  <p>Does version one copy a vector to another? If yes then it is slow if the vector is big.</p>