Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
while(!FP.eof()) is reading the last data point of the file twice
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="ramana, post: 3194362"] 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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
while(!FP.eof()) is reading the last data point of the file twice
Top