title: Extract range of elements from char array into string
body: <p>I want to extract a range of elements from the beginning of a char array and put them into a string. The range may be less than or equal to the number of elements.</p>
  
  <p>This is what I have come up with.</p>
  
  <pre><code>// buffer is a std::array&lt;char, 128&gt;
  
  std::string message;
  
  for (int i = 0; i &lt; numberToExtract; ++i)
  {
      message += buffer.at(i);
  }
  </code></pre>
  
  <p>Is there a better way to do this? </p>
  
  <p>I've been looking at something like std::string's iterator constructor. E.g.  <code>std::string(buffer.begin(), buffer.end())</code> but I don't want all the elements.</p>
  
  <p>Thanks.</p>