0
#include <iostream>
#include <string.h>
#include <sstream>
using namespace std;
int main(int argc, char *argv[]){
int n, aux;
string hexa="";
stringstream hexa_aux;
cin >> n;
while(n != 0){
aux = n % 16;
n/=16;
switch (aux){
case 10:
hexa+="A";
break;
case 11:
hexa+="B";
break;
case 12:
hexa+="C";
break;
case 13:
hexa+="D";
break;
case 14:
hexa+="E";
break;
case 15:
hexa+="F";
break;
default:
hexa_aux << aux;
hexa+=hexa_aux.str();
break;
}
}
for(int i = hexa.length()-1; i>=0; i--){
cout << hexa[i];
}
return 0;
}
I’m having trouble converting an integer to string
, when the input is 36, the right result should be 24, but the value ends up coming out 244, among other values.
The problem is with conversion?