title: How to push binary data into std::string?
body: <p>Im trying to create a binary file in the following way:</p>
  
  <pre><code>string buf;
  ...
  buf += filename.length();
  buf += filename;
  </code></pre>
  
  <p>etc. So first i give the length in binary format, but how do i convert this into a 4 byte char array, or 2 byte etc? basically i want to achieve the same functionality as this would:</p>
  
  <pre><code>int len = filename.length();
  fwrite(&amp;len, sizeof(len), 1, fp);
  </code></pre>
  
  <p>Which works fine, but having it in one string might be easier to process.</p>
  
  <p><strong>Edit:</strong> i dont want to use streams, nor vector, im trying to find out if its possible with strings.</p>