English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
这是将字符串转换为double的示例。
#include <iostream> using namespace std; int main() { char s[20] = "18.2894 is a number"; char *p; double result; result = strtod(s, &p); cout<<"The number after conversion of string : "<<result; return(0); }
输出结果
The number after conversion of string : 18.289400
在上述程序中,声明了一个用字母数字字符初始化的char类型数组s [20]。该函数strtod()
用于将该字符串转换为双数。
char s[20] = "18.2894 is a number"; char *p; double result; result = strtod(s, &p);