reading data character by character from text file
doubles values are stored in text file. 23.5 36.8 34.2 my teacher has advised me to read them character by character and then make words, like i have to read "2" "3" "." "5" and now have to make it or treat it as word and then using atoi() i have to convert it into double. but i dont know how to do this could anyone plz explain with some code relevant to my example. im new to filing so pardon me for basic questioning
Re: reading data character by character from text file
Can be done, but why?
Why not just read the floating values:
Code:
std::ifstream input("test.txt");
double d;
while (input >> d) {
std::cout << "Read " << d << "\n";
}
Re: reading data character by character from text file
following errors incured
error C2065: 'input' : undeclared identifier
E:\MyProjects\practice\practice.cpp(54) : error C2296: '>>' : illegal, left operand has type 'double'
E:\MyProjects\practice\practice.cpp(54) : error C2297: '>>' : illegal, right operand has type 'double'
Re: reading data character by character from text file
It would help if you showed us the code too.
Re: reading data character by character from text file
double d;
//char ch;
ifstream file("E:\\abc.txt");
if(!file)
{
cout<<"error";
exit(1);
}
while(input>>d)
{
std::cout<<d;
}
file.close();
getch();
Re: reading data character by character from text file
You declared your ifstream to be named file, then you used the name input. You should be consistent.