title: How to resize std::string to remove all null terminator characters?
body: <p>I'm using a <code>std::string</code> to interface with a C-library that requires a <code>char*</code> and a length field:</p>
  
  <pre><code>std::string buffer(MAX_BUFFER_SIZE, '\0');
  TheCLibraryFunction(&amp;buffer[0], buffer.size());
  </code></pre>
  
  <p>However, the <code>size()</code> of the string is the actual size, not the size of the string containing actual valid non-null characters (i.e. the equivalent of <code>strlen()</code>). What is the best method of telling the <code>std::string</code> to reduce its size so that there's <s>only 1 ending null terminator character</s> no explicit null terminator characters? The best solution I can think of is something like:</p>
  
  <pre><code>buffer.resize(strlen(buffer.c_str()));
  </code></pre>
  
  <p>Or even:</p>
  
  <pre><code>char buffer[MAX_BUFFER_SIZE]{};
  TheCLibraryFunction(buffer, sizeof(buffer));
  std::string thevalue = buffer;
  </code></pre>
  
  <p>Hoping for some built-in / "modern C++" way of doing this.</p>
  
  <h2>EDIT</h2>
  
  <p>I'd like to clarify the "ending null terminator" requirement I mentioned previously. I didn't mean that I want 1 null terminator explicitly in <code>std::string</code>'s buffer, I was more or less thinking of the string as it comes out of <code>basic_string::c_str()</code> which has 1 null terminator. However for the purposes of the <code>resize()</code>, I want it to represent the size of <em>actual</em> non-null characters. Sorry for the confusion.</p>