Mar 26
2008将字符串转换为double型值
Filed Under (c++) by boymg on 26-03-2008
函数名: strtod
功 能: 将字符串转换为double型值
用 法: double strtod(char *str, char **endptr);
程序例:
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- char input[80], *endptr;
- double value;
- printf("Enter a floating point number:");
- gets(input);
- value = strtod(input, &endptr);
- printf("The string is %s the number is %lf\n", input, value);
- return 0;
Code: ( cpp )
- #include <string>
- #include <iostream>
- #include <sstream>
- using namespace std;
- /* console cpp file */
- int main()
- {
- char data [] = "1234.5";
- double result;
- stringstream converter(data);
- converter >> result;
- cout << result << endl;
- return 0;
- }
