I was solving the following problem: Reverse the digits of an integer. Now the code for the problem is straightforward.
void reverse(int x){
   if(x < 0){
      cout << "-";
      x*=(-1);
   }
   while(x!=0){
      cout << x%10;
      x/=10;
   }
}
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?
 
     
     
     
     
     
     
    