关于程序中int超过范围的问题
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n,k;
char *s; //存k进制,或用数组s[100]
s=(char*)malloc(sizeof(int)); //s = new char(4); 也可以
memset(s, '\0', sizeof(int));
while(1)
{
cout<<"输入要转化的数(输入小于0的数退出程序):";
cin>>n;
if(n<0)
{
break;
}
cout<<"请输入要转化的进制";
cin>>k;
itoa(n,s,k); //将n转为k进制
cout<<"转化为%d进制是:"<<s<<endl;
}
return 0;
}
如果说是int越界,那输入1000000000为什么可以呢?但是再多加一个0就不可以了。