![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I convert string to double in C/C++?
Here is an example to convert a string to double.
Example
#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); }
Output
The number after conversion of string : 18.289400
In the above program, a char type array s[20] is declared which is initialized with a alphanumeric characters. The function strtod() is used to convert that string into a double number.
char s[20] = "18.2894 is a number"; char *p; double result; result = strtod(s, &p);
Advertisements