Using strtod to convert string to double - C++ Data Type

C++ examples for Data Type:double

Description

Using strtod to convert string to double

Demo Code

#include <iostream> 
#include <cstdlib> // strtod prototype 
using namespace std; 

int main() /*from   ww w.  ja va  2 s .  co m*/
{ 
    double d; 
    const char *string1 = "51.2% are admitted test test "; 
    char *stringPtr; 

    d = strtod( string1, &stringPtr ); // convert characters to double 

    cout << "The string \"" << string1 
        << "\" is converted to the\ndouble value " << d 
        << " and the string \"" << stringPtr << "\"" << endl; 
}

Result


Related Tutorials