我的CString 转化到int的实现,请问有简便方法吗?
void CMyDialog::OnBnClickedButton1()
  {    CString s;
    CEdit* edit1=(CEdit*)GetDlgItem(IDC_EDIT1);
    edit1->GetWindowTextA(s);
  
    int loop;
    int len=s.GetLength();  
    char c;
    int *i1=new int [len];
    for(loop=0;loop<len;loop++)

c=s.GetAt(loop);
i1[loop]=atoi(&c);
}
    
    int cym=0;
    for(loop=0;loop<len;loop++)
{
cym=cym*10;
cym=cym+i1[loop];
}    s.Format(_T("%d"),cym);
    CEdit* edit2=(CEdit*)GetDlgItem(IDC_EDIT2);
    edit2->SetWindowTextA(s);
    delete []i1;
  }

解决方案 »

  1.   

    string s = CString::getBuffer(CString::getLength());
    int a = atoi(s);
      

  2.   

    CString s;
    GetDlgItem(IDC_EDIT1)->GetWindowText(s);
    int b=atoi(s.GetBuffer(s.GetLength());
      

  3.   

    CString a("123");
    int b=atoi(a);//这里b=123了
      

  4.   

    直接用atoi()就可以
    可以对CString 直接转换
      

  5.   

    fprintf(整型存储变量,"%格式",CString字符串); 
      

  6.   

    CString str;
    int n = atoi(str.GetBuffer(str.GetLength());
    str.ReleaseBuffer();
    要记得ReleaseBuffer哦!