哎,我帖了吧
atoi,atof,aotl是一系列将字符串类型转换成整型,浮点型,长整型的函数,具体看帮助
我使用了一种实现方法,虽然比较麻烦,但应该更容易自己控制
CString cc,cstmp;
char aa[5]="789";
char bb[5]="123";
cc="";
int iReslt,iMod,iTmp,iStrlen,iCount,iaa,ibb;
iaa=0;
ibb=0;
iStrlen=strlen(aa);
for (iCount=0 iCount<iStrlen iCount++)
{
switch (aa[iCount]) {
case '0':iaa=iaa*10+0;break;
case '1':iaa=iaa*10+1;break;
case '2':iaa=iaa*10+2;break;
case '3':iaa=iaa*10+3;break;
case '4':iaa=iaa*10+4;break;
case '5':iaa=iaa*10+5;break;
case '6':iaa=iaa*10+6;break;
case '7':iaa=iaa*10+7;break;
case '8':iaa=iaa*10+8;break;
case '9':iaa=iaa*10+9;break;
}
}
iStrlen=strlen(bb);
for (iCount=0 iCount<iStrlen iCount++)
{
switch (bb[iCount]) {
case '0':ibb=ibb*10+0;break;
case '1':ibb=ibb*10+1;break;
case '2':ibb=ibb*10+2;break;
case '3':ibb=ibb*10+3;break;
case '4':ibb=ibb*10+4;break;
case '5':ibb=ibb*10+5;break;
case '6':ibb=ibb*10+6;break;
case '7':ibb=ibb*10+7;break;
case '8':ibb=ibb*10+8;break;
case '9':ibb=ibb*10+9;break;
}
}
iReslt=iaa-ibb;
while (iReslt>0 )
{
iTmp=iReslt;
iReslt=iReslt/10;
iMod=iTmp%10;
switch (iMod ){
case 0:cstmp=48;cc += cstmp;break;
case 1:cstmp=49;cc += cstmp;break;
case 2:cstmp=50;cc += cstmp;break;
case 3:cstmp=51;cc += cstmp;break;
case 4:cstmp=52;cc += cstmp;break;
case 5:cstmp=53;cc += cstmp;break;
case 6:cstmp=54;cc += cstmp;break;
case 7:cstmp=55;cc += cstmp;break;
case 8:cstmp=56;cc += cstmp;break;
case 9:cstmp=57;cc += cstmp;break;
}
}
MessageBox(cc);
其中两个FOR循环可以包装成带参数的字符串型转换成整型的函数,
WHILE循环可以包装成带参数的整形转换成字符串的函数
把上面代码加入一个按钮事件中就可以了。
给分?