atof() - Utility Function
How is Utility function "atof()" used in C++?
How to convert a string to double value?
is a Utility Function that converts a string into a double value. The string must contain a valid floating pointer number and the string is terminated by white space, punctuation except periods, characters except "e", "E".
double atof(const char *str);
cout << "Enter a valid string with
floating number" << endl;
cin >> arr;
cout<<"Value returned by atof is:: "<< atof(arr) << endl;
cout<<"Bytes occupied is::" << sizeof(atof(arr)) << endl;
Enter a valid string with floating number
Value returned by atof is:: 45
Bytes occupied is:: 8
In the above example atof() is used to convert a string with a floating point integer, by terminating the string when the character "h" is found. The floating point number alone is converted to a double value.