title: c++ std::cout in hexadecimal
body: <p>I have an output statement with <code>printf</code> in C++ that looks like this:</p>
  
  <pre><code>for(int i=0; i&lt;6; i++)
          printf("%.2X", (unsigned char) iter-&gt;hwaddress[i]);
  </code></pre>
  
  <p>I need to do the output with <code>std::cout</code>, I have tried to do it like this:</p>
  
  <pre><code>for(int i=0; i&lt;6; i++)
     cout &lt;&lt; hex &lt;&lt; (unsigned char) iter-&gt;hwaddress[i];
  </code></pre>
  
  <p>but that just gives me:</p>
  
  <pre><code>  �:�:w:�:�:
  </code></pre>
  
  <p>Does anyone know how to do this?</p>