#ifndef _tstof
  #ifdef _UNICODE    double __cdecl _tstof( const wchar_t *ptr )
    {
      CHAR astring[20];
      WideCharToMultiByte( CP_ACP, 0, ptr, -1, astring, 20, NULL, NULL);
      return atof(astring);
    }  #else
    #define _tstof atof
  #endif
#endif

解决方案 »

  1.   

    一句一句来:
    #ifndef _tstof // 如果没有定义_tstof,才编译以下代码
    #ifdef _UNICODE // 分Unicode和非Unicode处理double __cdecl _tstof( const wchar_t *ptr ) // UNICODE程序中使用函数转换为ANSI,再转换为浮点数
    {
    CHAR astring[20];
    WideCharToMultiByte( CP_ACP, 0, ptr, -1, astring, 20, NULL, NULL);// 转换为ANSI字符串
    return atof(astring); // 转换为浮点数
    }#else
    #define _tstof atof // 非UNICODE中直接定义为atof函数
    #endif
    #endif
      

  2.   

    如果定义了_UNICODE(也就是使用了unicode了),就吧_tstof函数先进行unicode转multibyte(即ANSI字编码),再调用crt的atof进行字符串到浮点的转换,如果没有定义_UNICODE(即没有使用unicode编码),就把_tstof直接映射为crt的atof。
    总的来说,由于crt的atof只能接收ansi字符串,无法接受unicode字符串,所以当使用unicode时就要进行unicode到ansi的转换才能调用crt的atof进行字符串到浮点的转换。