#include <iostream>
#include <string>
using namespace std;
string IntoStr(
int num)
{
int temp =
0;
int sign =
0;
string str =
"",result =
"";
if (num <
0)
{
num = -num;
sign =
1;
}
while (num)
{
temp = num %
10;
str += temp+
'0';
num = num /
10;
}
if (sign)
str +=
'-';
reverse(str.begin(), str.end());
return str;
}
int main()
{
int num1 =
12345;
int num2 = -
6789;
cout << IntoStr(num1) << endl;
cout << IntoStr(num2) << endl;
system(
"pause");
return 0;
}
测试:
转载请注明原文地址: https://ju.6miu.com/read-1291051.html