各位大侠:请问在VC中怎么把CString类型转换为int 类型?
很急的!谢谢!

解决方案 »

  1.   

    CString strTest("123");
    int n = ::atoi(strTest);
      

  2.   

    atoi()就可以了!
    给你看一下MSDN中的例子
    #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 );
    }
      

  3.   

    那如果我想把int型变成string型怎么办那?