如何在C / C ++中将字符串转换为双精度?
这是将字符串转换为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);
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短