如何在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);
热门推荐
5 甄嬛传祝福语简短
10 對好友毕业祝福语简短
11 新年祝同学祝福语简短
12 圣诞简短祝福语给父母
13 送礼祝福语男性生日简短
14 对睡觉的祝福语简短
15 感动妈妈的祝福语简短
16 升职祝福语朋友简短精辟
17 简短祝福语中考女孩的话
18 麻辣拌店祝福语简短