数组下标的无效类型“int[int]" [英] invalid types 'int[int]' for array subscript
本文介绍了数组下标的无效类型“int[int]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码抛出了标题中给出的编译错误,谁能告诉我要更改什么?
This code throws up the compile error given in the title, can anyone tell me what to change?
#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; ++x){
for (int y = 0; y <= 9; ++y){
myArray[i][t][x][y] = i+t+x+y; //This will give each element a value
}
}
}
}
for (int i = 0; i <= 9; ++i){
for (int t = 0; t <=9; ++t){
for (int x = 0; x <= 9; ++x){
for (int y = 0; y <= 9; ++y){
cout << myArray[i][t][x][y] << endl;
}
}
}
}
system("pause");
}
提前致谢
推荐答案
您正在对一个三维数组 myArray[10][10][10]
下标四次 myArray[i][t][x][y]
.您可能需要向数组添加另一个维度.还可以考虑像 Boost.MultiArray 这样的容器,尽管此时您可能已经想不通了.
You are subscripting a three-dimensional array myArray[10][10][10]
four times myArray[i][t][x][y]
. You will probably need to add another dimension to your array. Also consider a container like Boost.MultiArray, though that's probably over your head at this point.
这篇关于数组下标的无效类型“int[int]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文