I've read through the questions asked regarding how to do this, but none have worked. I am trying to read in weather temperatures from a file (type doubles). I am supposed to read them using a 2D array (I do not know how many rows, but I know how many columns). After I read them in, I want to display them to see if it worked.
int numRows;
int numCols = 12;
int i = 0;
string line;
while (!inFile.eof()) // Count the number of rows.
{
getline(inFile, line);
i++;
}
inFile.close();
numRows = i;
cout << "There are: " << numRows << " rows in this file." << endl;
cout << line << endl;
double TempNum;
double **Temps;
Temps = new double*[numRows];
for (int row = 0; row < numRows; row++)
Temps[row] = new double[numCols];
while (!inFile.eof())
{
inFile >> Temps[numRows][numCols];
}
inFile.close();
// Want to print on screen to see if it worked.
for (int row = 0; row < numRows; row++)
{
for (int col = 0; col < numCols; col++)
cout << Temps[numRows][numCols];
}
I know looking at it that I am missing something regarding how to get the actual Temperature numbers themselves inside the rows & columns, but I can't figure it out. What am I doing wrong?