title: Getting a buffer into a stringstream in hex representation:
body: <p>If I had a buffer like:</p>
  
  <pre><code>uint8_t buffer[32];
  </code></pre>
  
  <p>and it was filled up completely with values, how could I get it into a stringstream, in hexadecimal representation, with 0-padding on small values?</p>
  
  <p>I tried:</p>
  
  <pre><code>std::stringstream ss;
  for (int i = 0; i &lt; 32; ++i)
  {
      ss &lt;&lt; std::hex &lt;&lt; buffer[i];
  }
  </code></pre>
  
  <p>but when I take the string out of the stringstream, I have an issue: bytes with values &lt; 16 only take one character to represent, and I'd like them to be 0 padded.</p>
  
  <p>For example if bytes 1 and 2 in the array were {32} {4} my stringstream would have:</p>
  
  <pre><code>204 instead of 2004
  </code></pre>
  
  <p>Can I apply formatting to the stringstream to add the 0-padding somehow?  I know I can do this with sprintf, but the streams already being used for a lot of information and it would be a great help to achieve this somehow.</p>