来自MSDN的函数原型:
原型一:double strtod(const char *nptr, char **endptr);
原型二:double _strtod_l(const char *nptr, char **endptr, _locale_t locale);
原型三:double wcstod(const wchar_t *nptr, wchar_t **endptr);
原型四:double wcstod_l(const wchar_t *nptr, wchar_t **endptr, _locale_t locale);
其中:
nptr --- 需要转换的字符串(Null-terminated string to convert.)
endptr --- 存储扫描结束位置的指针(Pointer to character that stops scan.)
locale --- 区域代码(The locale to use.)
这个函数扫描字符串中的数字,直到第一个非字符串结束,并将位置存到指针endptr中。
举例说明:
WCHAR *string, *stopstring;
double x;
string = L"3.1415926This stopped it";
x = strtod( string, &stopstring );
printf( "string = %s/n", string );
printf(" strtod = %f/n", x );
printf(" Stopped scan at: %s/n/n", stopstring );
输出结果:
string = 3.1415926This stopped it
strtod = 3.141593
Stopped scan at: This stopped it