class Solution {
public:
int reverse(int x) {
int re;
string s = to_string(x);
auto l = s.begin();
auto r = prev(s.end());
if(*l=='-')l++;
while(l<r){
char temp = *l;
*l = *r;
*r = temp;
l++;
r--;
}
try{
re = stoi(s);
}catch(exception e){
re = 0;
}
return re;
}
};
to_string函数是将int型或者浮点型转换为字符串
stoi函数是将string类型转换为string类型的。
atoi函数是将char* 类型的转换为string类型