代码如下:CString m_s="55";
int m_i;因为"55"是数字,怎样把m_s的字符串转换成数值赋给m_i ?一个有几种方法?请各位高手教一下.

解决方案 »

  1.   

    str.format("%d",...)
    int i
    wprintf(i,...)
      

  2.   

    同意楼上做法。
    先转为char *,在用atoi转变。
      

  3.   

    有一个变通的办法,可以试试看哦:
    在对话框中加入一个编辑框控件ID_EDIT1,然后再在ClassWizard中给它绑定一个CString变量m_sStr和一个整型变量m_nNum,然后执行下面语句:
    m_sStr = "55";
    UpdateData(false);
    UpdateData(true);这时候m_nNum应该等于55。
      

  4.   

    楼上的,没搞错吧,一个控件怎可同时绑定两个变量呢?
    我觉得用atoi()还是可以的,我试过开始把char型转换成int 型。
    所以只要合适地把CString转换成char 型就可了。
      

  5.   

    Example/* ATOF.C: This program shows how numbers stored
     * as strings can be converted to numeric values
     * using the atof, atoi, and atol functions.
     */#include <stdlib.h>
    #include <stdio.h>void main( void )
    {
       char *s; double x; int i; long l;   s = "  -2309.12E-15";    /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "7.8912654773d210";  /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "  -9885 pigs";      /* Test of atoi */
       i = atoi( s );
       printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );   s = "98854 dollars";     /* Test of atol */
       l = atol( s );
       printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
    }
    Outputatof test: ASCII string:   -2309.12E-15   float:  -2.309120e-012
    atof test: ASCII string: 7.8912654773d210   float:  7.891265e+210
    atoi test: ASCII string:   -9885 pigs      integer: -9885
    atol test: ASCII string: 98854 dollars      long: 98854
      

  6.   

    CString string;
    int number;
    string = "1234";
    number = atoi(string);
      

  7.   

    保证可以运行CString b="1131";
    int ss=0;
    ss=atoi(b);
      

  8.   

    定義了unicode
    _wtoi((TCHAR*)(LPCTSTR)b);
    沒有
    atoi((char*)(LPCTSTR)b);
    http://www.csdn.net/Develop/Read_Article.asp?id=12365
    http://www.vckbase.com/study/article/data_convert.htm
      

  9.   

    怎样把m_i的数值转换成字符串值赋给m_s ?
      

  10.   

    怎样把m_i的数值转换成字符串值赋给m_s ?
      

  11.   

    int n;
    CString str;sprintf( n,"%d", str );
      

  12.   

    哈哈哈, 反了sprintf( str, "%d", n );