C++ (对于C+;+;)读取类型从文件加倍到2D数组中

C++ (对于C+;+;)读取类型从文件加倍到2D数组中,c++,arrays,C++,Arrays,我已经通读了关于如何做到这一点的问题,但没有一个有效。我试图从一个文件中读取天气温度(键入doubles)。我应该使用2D数组读取它们(我不知道有多少行,但我知道有多少列)。在我读入它们之后,我想显示它们,看看它是否有效 int numRows; int numCols = 12; int i = 0; string line; while (!inFile.eof()) // Count the number of rows. { getline(inFile, line);

我已经通读了关于如何做到这一点的问题,但没有一个有效。我试图从一个文件中读取天气温度(键入doubles)。我应该使用2D数组读取它们(我不知道有多少行,但我知道有多少列)。在我读入它们之后,我想显示它们,看看它是否有效

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];
}
int numRows;
int numCols=12;
int i=0;
弦线;
而(!infle.eof())//计算行数。
{
getline(填充,行);
i++;
}
infle.close();
numRows=i;

cout您需要为行指定一个数字。编译器需要知道在执行之前为数组保留多少内存。

我看了这个问题,但我的问题不同。我正在读一个二维数组,它是一个双精度数组。这个问题不包括二维动态计算数组。它确实包括为什么
而(!infle.eof())
是错误的。但是我该如何为行指定一个数字呢?从技术上讲,我可以对行和列使用typedouble,因为它的温度都很高。行表示年份,列表示月份。我把TempNum放在那里,但我不知道如何将它包含在2d动态数组中。请认真使用
std::vector
。即使您想要固定大小的数组,也可以使用
std::array
我们还没有学习向量,所以我不知道如何做到这一点。为什么我要使用std来定义数组的范围?