0

I'm reading a book "Guide to Scientific Computing in C++" and there is a code inside the book that doesn't run as supposed to do.

Here is the listing from the book as follows:

#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

int main()
{
int x[6], y[6];
ifstream read_file("Output.dat");
assert(read_file.is_open());

int i = 0;
while (!read_file.eof())
{

    read_file >> x[i] >> y[i];
    cout <<x[i]<<" "<< y[i]<<"\n";
    i++;

}
read_file.close();
return 0;
}

Here is my "output.dat":

0 0
1 0
0 1
0 0
1 0
0 1

When I run the program, I get :

0 0
1 0
0 1
0 0
1 0
0 1
4195984 807

So I wonder why it outputs the trash data in the last line which is not in my data file.

ofenerci
  • 159
  • 1
  • 5

0 Answers0