Just registered but you guys have been a big help for the whole semester. I have what seems to be a simple problem but I'm just stuck. My assignment is a game of life sim that prompts the user for an input file, and then reads integers from the file that represent coordinates of the cells (row/column). After that, it does its thing until the user decides it should stop. I designed it originally to get the values from the keyboard (enter two integers between 1-20 with a space inbetween until negatives are read) because I thought it would be easy to change my cin's to fin's but I'm having some trouble. As of now, the file seems to open but the grid is blank. Here's the section of relevant code:
int main()
{
ifstream datafile;
string filename;
cout << "The input values from the file will begin the first generation." << endl << endl;
cout << "Follow the prompts to create new generations or terminate the program." << endl << endl;
// Initilize the grid to all dead cells
bool Grid[Size][Size];
for (int i=0; i < Size; i++)
for (int j=0; j < Size; j++)
Grid[i][j] = false;
int row, col;
// Prompt user for filename.
cout << "Please enter the file name containing input values. " << endl;
cout << endl;
cin >> filename;
cout << fixed << showpoint;
datafile.open(filename.c_str());
if (!datafile)
{
cout << "File not found" << endl;
return 1;
}
while (datafile)
{
datafile >> row >> col;
}
if ( row>=0 && row<Size && col>=0 && col<Size) // if legal row-col
Grid[row][col] = true;
while ( row != -1);
displayGrid(Grid);
And here's how the input file is setup:
1 2
3 3
5 5
13 4
17 5
12 12
5 19
-1 -1
Any help would be appreciated. Thanks in advance.