title: C++ copy std::string to char array with no null termination
body: <p>I am writing to a binary file using a struct that just contains a char[32]. I basically need to format each block of data by performing various calculations on string arrays and concatenating the results. I am attempting to copy an std::string to a char array with no null termination. The more I read into this, the more confused I get. If I do:</p>
  
  <pre><code>struct block{
      char data[32];
  };
  block blocks[2048];
  std::string buffer;
  
  buffer = "12345678123456781234567812345678";
  strcpy(blocks[0].data, buffer.c_str());
  </code></pre>
  
  <p>I get an error, because adding the null terminator with c_str() makes the string length 33. If I subtract one char from the string, it works, but then I have the null terminator, which I don't want. I can successfully do the following:</p>
  
  <pre><code>strcpy(blocks[0].data, "12345678123456781234567812345678");
  </code></pre>
  
  <p>but I want to construct the string first, since it often involves concatenating different strings from various arrays. For instance, I can do this with std::string:</p>
  
  <pre><code>std::string buffer = stringArray1[0] + stringArray2[0];
  strcpy(blocks[0].data, buffer.c_str());
  </code></pre>
  
  <p>but then I have the null terminator again. I'd just like to copy exactly the chars in the std::string with no null terminator.</p>
  
  <p>I am using VC++ 6.0.</p>