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*)'