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

C++ examples for Data Type:double

Description

Using atof to convert string to double

Demo Code

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

int main() //from   ww w  . ja v  a2  s.  co  m
{ 
    double d = atof( "99.0" ); // convert string to double 

    cout << "The string \"99.0\" converted to double is " << d 
        << "\nThe converted value divided by 2 is " << d / 2.0 << endl; 
}

Result


Related Tutorials