数组下标的无效类型'int [int]' [英] invalid types 'int[int]' for array subscript

查看:83
本文介绍了数组下标的无效类型'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆