How to convert string to double??

Hi everyone. I am working on a program which can read and get data from a file.
The file looks like this: 45.33
33.68
45.98

The program reads the file correctly. However I need to convert the data from string into double. Does anybody have any idea how to do it?

Here is the code that I have :
int DollarList::loadFile(const char* filename) {

Number save;
int a, i;
double d;
string b;

ifstream file (filename);

if (file.is_open ()) {

a = true;

for (i=0; ! file.eof(); i++){

getline (file,b);
b = atof (b);

cout << b << endl;

}

} else {

a = false;

}

return a;

}

when I compile it, my compiler shows this:

w3.cpp: In member function 'int DollarList::loadFile(const char*)':
w3.cpp:54: error: cannot convert 'std::string' to 'const char*' for argument '1' to 'double atof(const char*)'


Well, there's this as a starter:
http://www.cplusplus.com/articles/numb_to_text/

But you could always read the error message the compiler is giving you and fix it.
It is telling you exactly what the problem is.
haha yeah I know!! But the point is I don't know how to correct it ......
Topic archived. No new replies allowed.