R
ramana
I'm wondering if someone could point me to the flaw in the following
code that uses the while(!FP.eof()) condition to read the input data.
This condition is reading the last data point of the file twice.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
double x;
ifstream FP("test.d");
//while(!FP.eof()){FP >> x; cout << x << endl;} // This reads the
last data point of test.d twice
while(FP >> x){cout<< x << endl;} // This doesn't.
return 0;
}
/* Using either gcc 3.4.6 or gcc 4.1.3
File "test.d" has the following 2 data points:
1.1
2.2
*/
Thanks...ramana
code that uses the while(!FP.eof()) condition to read the input data.
This condition is reading the last data point of the file twice.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
double x;
ifstream FP("test.d");
//while(!FP.eof()){FP >> x; cout << x << endl;} // This reads the
last data point of test.d twice
while(FP >> x){cout<< x << endl;} // This doesn't.
return 0;
}
/* Using either gcc 3.4.6 or gcc 4.1.3
File "test.d" has the following 2 data points:
1.1
2.2
*/
Thanks...ramana