2 回答

泛舟湖上清波郎朗
TA貢獻(xiàn)1818條經(jīng)驗 獲得超3個贊
int int_a;
string string_a;
char temp[128];
int_a=10;
sprintf(temp,"%d",int_a);
string_a=(string)(temp);
先將整型轉(zhuǎn)換成char[]字符串,然后再轉(zhuǎn)換成string咯

www說
TA貢獻(xiàn)1775條經(jīng)驗 獲得超8個贊
#define MAX_DIGITS_INT 10
void IntToStr( int num ,char str[] )
{
int i = 0, j = 0;
int isNeg = 0;
char temp[MAX_DIGITS_INT + 2];
if( num<0 )
{
num* = -1;
isNeg = 1;
}
do
{
temp[i++] = (num%10) + '0';
num/ = 10;
}while(num);
if( isNeg )
temp[i++] = '-1';
while(i>0)
str[j++] = temp[--i];
str[j] = '\0';
}
添加回答
舉報
0/150
提交
取消