答案如下:
void Convert()
{
map<int ,string> maps;
maps[0]="0";
maps[1]="1";
maps[2]="2";
maps[3]="3";
maps[4]="4";
maps[5]="5";
maps[6]="6";
maps[7]="7";
maps[8]="8";
maps[9]="9";
for (int i=10,j=65;i<36,j<91;i++,j++)
{
maps[i]=(char)j;
}
cout<<"请输入要转换的数字:";
stack<int> stack1;
int num;
int lis;
int rs;
cin>>num;
cout<<"请输入要转换的目标进制数:";
cin>>lis;
while(num!=0)
{
rs=num%lis;
num=num/lis;
stack1.push(rs);
}
string buffer;
for (int k=stack1.size();k>0;k--)
{
int m=stack1.top(); buffer+=maps[m];
stack1.pop();
}
switch(buffer.size())
{
case 3:
buffer="0"+buffer;
break;
case 2:
buffer="00"+buffer;
break;
case 1:
buffer="000"+buffer;
break;
case 0:
buffer="0000";
break;
default:
break;
} cout<<buffer<<endl;
}
有错误或者好的建议 请指出!