// crt_atof.c
#include <stdlib.h>
#include <stdio.h>int main( void )
{
   char *s; double x; int i; long l;   s = "  -2309.12E-15";    /* Test of atof */
   x = atof( s );
   printf( "atof test: \"%s\"; float:  %e\n", s, x );   s = "7.8912654773d210";  /* Test of atof */
   x = atof( s );
   printf( "atof test: \"%s\"; float:  %e\n", s, x );   s = "  -9885 pigs";      /* Test of atoi */
   i = atoi( s );
   printf( "atoi test: \"%s\"; integer: %d\n", s, i );   s = "98854 dollars";     /* Test of atol */
   l = atol( s );
   printf( "atol test: \"%s\"; long: %ld\n", s, l );
}
结果:
atof test: "  -2309.12E-15"; float:  -2.309120e-012
atof test: "7.8912654773d210"; float:  7.891265e+210
atoi test: "  -9885 pigs"; integer: -9885
atol test: "98854 dollars"; long: 98854觉得C++太好了,Delphi就是比不上。

解决方案 »

  1.   

    IntToStrDef,不过后面夹带字符的无法正确转换,我不知道是否有其他内置函数。
    对于夹带字符的,本身就不能划作数字范畴,这个属于概念错误。
      

  2.   

    当然有啦,strtoInt,intTostr,FloatToStr,StrToFloat...
      

  3.   

    说明一下,各位没有发现
       s = "98854 dollars";     /* Test of atol */
       l = atol( s );
    数字+字符,只转化字符?
      

  4.   

    我以为这并不能以这个例子说明C++就比Delphi好,虽然我也认为在某些方面确实是这样