我正在尝试运行一个 3d 数组,但是当我运行它时代码在 Windows 中崩溃了,这是我的代码;
#include <iostream>
using namespace std;
int main(){
int myArray[10][10][10];
for (int i = 0; i <= 9; ++i){
for (int t = 0; t <=9; ++t){
for (int x = 0; x <= 9; ++t){
myArray[i][t][x] = i+t+x;
}
}
}
for (int i = 0; i <= 9; ++i){
for (int t = 0; t <=9; ++t){
for (int x = 0; x <= 9; ++t){
cout << myArray[i][t][x] << endl;
}
}
}
system("pause");
}
谁能给我一个快速修复/解释
最佳答案
你两次有这条线
for (int x = 0; x <= 9; ++t){
当你的意思
for (int x = 0; x <= 9; ++x){
经典的复制粘贴错误。
顺便说一句,如果您在调试器中运行它并查看变量的值,就很容易看出发生了什么。
关于C++ 3d数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/360449/