title: How to output a character as an integer through cout?
body: <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {  
      char          c1 = 0xab;
      signed char   c2 = 0xcd;
      unsigned char c3 = 0xef;
  
      cout &lt;&lt; hex;
      cout &lt;&lt; c1 &lt;&lt; endl;
      cout &lt;&lt; c2 &lt;&lt; endl;
      cout &lt;&lt; c3 &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I expected the output are as follows:</p>
  
  <pre><code>ab
  cd
  ef
  </code></pre>
  
  <p>Yet, I got nothing.</p>
  
  <p>I guess this is because cout always treats 'char', 'signed char', and 'unsigned  char' as characters rather than 8-bit integers. However, 'char', 'signed char', and 'unsigned  char' are all integral types.</p>
  
  <p>So my question is: How to output a character as an integer through cout?</p>
  
  <p>PS: static_cast(...) is ugly and needs more work to trim extra bits.</p>