CString str="25";
int a,b;怎么样让a取到str中的整数2值?也就让从str中取让
a=2
b=5

解决方案 »

  1.   

    a = atoi(str.GetAt(0));
    b = atoi(str.GetAt(1));
      

  2.   

    a = str.GetAt(0)-0x30; 
    b = str.GetAt(1)-0x30;atoi 是字符串转数字
    getAt 得到的是字符
    如果用atoi的话
    a=atoi(str.Mid(0,1))
      

  3.   

    #include <iostream.h>
    void main()
    {
    char *str="25";
    int a,b;
    a=str[0]-0x30;
    b=str[1]-0x30;
    cout<<a<<","<<b<<endl;
    }
    这是一个小的测试用程序。。
      

  4.   

    #include <iostream.h> 
    void main() 

    char *str="25"; 
    int a,b; 
    a=atoi(str[0]); 
    b=atoi(str[1]); ; 
    cout < <a < <"," < <b < <endl; 

      

  5.   

    CString str="25"; 
    int a,b; a = str.GetAt(0)-'0';
    b = str.GetAt(1)-'0';
      

  6.   

    atoi 的话要加头文件 <math.h>
      

  7.   

    与<math.h>头文件没有关系,是类型不想同!难道就没有高人能解答这个问题?
      

  8.   

    楼上那么多正确的代码你不用,,还问1.CString str="25"; 
    int a,b; a = str.GetAt(0)-'0';
    b = str.GetAt(1)-'0';
    2.CString str="25"; 
    int a,b; a = atoi(str.Mid(0,1));
    b = atoi(str.Mid(1,1));
      

  9.   

    CString str="25";
    int a,b;
    a = atoi(str);
    b = a%10;
    a /= 10;
     
      

  10.   

    a=atoi(str.Mid(0).Left(1));
    b=atoi(str.Mid(1).Left(1));