整型如何转化为字符型?
将1234转化为"1234",请问怎么转化??
回复 楼主 阿冲
#include <iostream>#include <cstring>
using namespace std;
int main()
{
int num;
char str[11], strtemp[11];
while (cin>>num){
int pn = 0;
while (num!=0){
str[pn++] = num %10 + '0';
num /= 10;
//cout<<str[pn]<<endl;
}
str[pn] = '\0';
int i = 0;
for (int k=pn-1; k>=0; k--){
strtemp[i++] = str[k];
}
strtemp[pn] = '\0';
cout <<strtemp<<endl;
}
return 0;
}
看看这个行不行!