स्ट्रिंग को डबल में बदलने का एक उदाहरण यहाँ है।
उदाहरण
#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);