You can read from the file like this:
1 2 3 4 5 6 7 8
|
int row = 0;
int a, b, c, d;
while ( (row < 6) && (inFile >> a >> b >> c >> d) )
{
cout << a << " " << b << " " << c << " " << d << " " << endl;
row++;
}
|
Here, the variable
int row
keeps track of how many rows have been read from the file.
The cout statement can be replaced by code to copy the values to the array,
1 2 3 4
|
factories [row][0] = a;
factories [row][1] = b;
factories [row][2] = c;
factories [row][3] = d;
|
or indeed, get rid of a-d completely and just just put the factories array directly in the
infile >>
statement.
Note: I added an extra test
(row < 6)
in order to avoid running beyond the actual array, if for example the file had more than six lines of data.
On the other hand, after the loop has completed,
row
will hold the actual number of rows which were successfully read from the file.
Oh, one more thing, avoid looping on
eof()
, it often leads to errors, it is not recommended.