Hello All,
I am using the following code to read a string from a file and converting it to float for later comparision and stuff..
Code:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int main () {
string line;
float x;
const char* s;
ifstream myfile ("valseq");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
/*converting string to floating point value*/
x=atof(line.c_str());
cout << x;
return 0;
}
The output that i get is
i.e. 0.125933 for the first cout(which mst be the same for the second cout as well because the file contains this value.)and 0 for the second cout...
what am i doing wrong..Please HELP....
thanks