Hi Everyone, I am attempting to convert a c string to a float number with atof. But for some reason, atof always return an integer, which I really could not figure out why. Below is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <iostream>
usingnamespace std;
int main(){
string double_str = "0.0";
double d = atof(double_str.c_str());
cout << "double is: " << d << endl;
return 0;
}
Perhaps I am doing this wrong...but the result is always: