将CString 变为 int?

解决方案 »

  1.   

    Convert strings to double (atof), integer (atoi, _atoi64), or long (atol).double atof( const char *string );int atoi( const char *string );__int64 _atoi64( const char *string );long atol( const char *string );
      

  2.   

    atoi这类问题以前问的很多,建议每次提问前先去搜索一下,可以节省分数
      

  3.   

    CString temp=( "123" );        
    i = atoi(temp); 
      

  4.   

    atoi
    itoa
    查一下msdn,很详细
      

  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.   

    Convert strings to double (atof), integer (atoi, _atoi64), or long (atol).double atof( const char *string );int atoi( const char *string );__int64 _atoi64( const char *string );long atol( const char *string );
      

  7.   

    首先用atoi(char *)这个函数是没错的,但是CString类的变量不能直接当这个函数的参数,所以要这样用,
    CString temp="12345";
    int i=atoi(temp.GetBuffer(5));
    GetBuffer函数是把一个CString转化为一个char *类型
      

  8.   

    可用sscanf(CString ,"%i",int*);完成!
    很管理,具体可看msdn。我刚刚找了很久啊!你可是坐享其成!
      

  9.   

    http://www.csdn.net/Develop/Read_Article.asp?id=12365
    http://www.vckbase.com/study/article/data_convert.htm
      

  10.   

    static_cast<int>(CString ??)