title: Redirecting standard output to integer
body: <p>I was solving the following problem:
  <em>Reverse the digits of an integer.</em> Now the code for the problem is straightforward. </p>
  
  <pre><code>void reverse(int x){
     if(x &lt; 0){
        cout &lt;&lt; "-";
        x*=(-1);
     }
  
     while(x!=0){
        cout &lt;&lt; x%10;
        x/=10;
     }
  }
  </code></pre>
  
  <p>But the problem asked the answer to be returned as integer. So I was wondering is there any way the output stream can be redirected to an integer. I know I could redirect it to a string and then convert to integer. But is there any direct way? </p>