【发布时间】:2022-01-23 02:01:07
【问题描述】:
请,谁能告诉我为什么在编译以下代码后出现此错误。
int main()
{
std::ifstream input("graf2.txt", std::ios::in); // Input file...
std::list<int> lst; // For a Grapf constructor usage...
double mtx[MAX][MAX] = {0}; // For a Grapf consturctor usage...
if (!input.is_open())
{
std::cerr << "There was a problem opening the input file!\n";
exit(1); //exit or do additional error checking
}
else
{
double debths;
int i = 0, j = 0;
int check = 0;
while (input >> debths)
{
if (!check)
check = (int)debths;
else
mtx[i++][j++] = debths;
}
}
return 0;
}
错误: 在 SPA_round2.exe 中的 0x00007FF731C7CD0A 处引发异常:0xC0000005:访问冲突写入位置 0x000000BD153000C0。
MAX 定义为 100。在我的输入文件中,我有一个 13x13 矩阵。
【问题讨论】:
-
你可能有一个数组溢出。您也只是在填充矩阵的对角线。
-
mtx[i++][j++] = debths;所以你写信给mtx[0][0],然后是mtx[1][1],然后是mtx[2][2]...怎么样,然后是mtx[0][1]等等? -
是的,先生,谢谢。虽然需要更换循环......现在我的眼睛睁开了。感谢您的帮助。
-
"graf2.txt"里面有什么 -
第一行包含节点数。比矩阵。 'graf2.txt' , 'graf' 是 'Graph' 的塞尔维亚语拼写。
标签: c++ visual-c++