title: Why is it OK to return a 'vector' from a function?
body: <p>Please consider this code. I have seen this type of code several times. <code>words</code> is a local vector. How is it possible to return it from a function?</p>
  
  <p>Can we guarantee it will not die?</p>
  
  <pre><code> std::vector&lt;std::string&gt; read_file(const std::string&amp; path)
   {
      std::ifstream file("E:\\names.txt");
  
      if (!file.is_open())
      {
          std::cerr &lt;&lt; "Unable to open file" &lt;&lt; "\n";
          std::exit(-1);
      }
  
      std::vector&lt;string&gt; words;//this vector will be returned
      std::string token;
  
      while (std::getline(file, token, ','))
      {
          words.push_back(token);
      }
  
      return words;
  }
  </code></pre>