title: Why does conversion of int -> hex/oct/bin print as plain decimal value in output?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  int main() {
       // &lt;variables&gt;
       int t = 0b11011101;
  
       stringstream aa;
  
       int n;
       string hexed;
       int hexedNot;
       // &lt;/variables&gt;
  
       aa &lt;&lt; t;
       aa &gt;&gt; n;
       cout &lt;&lt; n &lt;&lt; endl; // output 221
       aa.clear();
  
       aa &lt;&lt; hex &lt;&lt; n;
       aa &gt;&gt; hexed;
       aa.clear();
  
       aa &lt;&lt; hex &lt;&lt; n;
       aa &gt;&gt; hexedNot;
       cout &lt;&lt; hexed &lt;&lt; endl; // output dd
  
       cout &lt;&lt; hexedNot; // output 221
  
       return 2137;
  }
  </code></pre>
  
  <p>I want to convert int decimals to hex/oct/bin ints with stringstream, but I don't know how to approach it properly. If I try to convert it to a string containing hex, it's fine, but when I try to do the same with an integer, it just doesn't work. Any ideas? I can't use c++11 and I want to do it in a really slim and easy way.</p>
  
  <p>I know that I can use <code>cout &lt;&lt; hex &lt;&lt; something;</code>, but that would just change my output and it wouldn't write the hexified value into my variable.</p>