五维数组?在c ++中? [英] Five dimensional array? in c++?

查看:178
本文介绍了五维数组?在c ++中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
using namespace std;
int main()
{
	//Allocate a four-dimensional 3x2x4x3x5 array of ints
	int***** ip4array=new int****[3];
	for(int i=0;i<3;++i)
	{
		ip4array[i]=new int***[2];
		for(int j=0;j<2;++j)
		{
			ip4array[i][j]=new int**[4];
			for(int k=0;k<4;++k)
			{
				ip4array[i][j][k]=new int*[3];
				for(int l=0;l<3;l++)
				{
					ip4array[i][j][k][l]=new int[5];
				}
			}
		}

	}
	//fill the array
	for(int i=0;i<3;++i)
	{
		for(int j=0;j<2;++j)
		{
			for(int k=0;k<4;++k)
			{
				for(int l=0;l<3;++l)
				{
					for(int m=0;m<5;++m)
					{
					ip4array[i][j][k][l][m]=i+j+k+l+m;
				}
				}
			}
		}
	}
	//output the array
	for(int i=0;i<3;++i)
	{
		for(int j=0;j<2;++j)
		{
			for(int k=0;k<4;++k)
			{
				for(int l=0;l<3;++l)
				{
					for(int m=0;m<5;++m)
					{
					cout<<ip4array[i][j][k][l][m]<<" ";
					}
					cout<<endl;
				}
				cout<<endl;
			}
			cout<<endl;
		}
		cout<<endl;
	}
	cout<<endl;
	//Deletiing the arrays
	for(int i=0;i<3;++i)
	{
		for(int j=0;j<2;++j)
		{
			for(int k=0;k<4;++k)
			{
				for(int l=0;l<3;++l)
				{
				delete ip4array[i][j][k][l];
			}
				delete ip4array[i][j][k];
			}
			delete ip4array[i][j];
		}
		delete [] ip4array[i];
	}
	delete[] ip4array;
	system("pause");
	return 0;

}





我的尝试:



程序显示错误,我不能有5维而不是它创建8维请有人??????????



What I have tried:

Program is showing bug and i am not able to have 5-dimensional instead it is creating 8 dimensional please can somebody??????????

推荐答案

你试过吗?

Did you try ?
int ip4array[3][2][4][3][5];


请看我对这个问题的评论。首先,你可以使用调试器,只是为了了解发生了什么,但可能你对这个概念有些困惑。这可以帮助您:多维数组 - C ++教程



-SA
Please see my comment to the question. First of all, you could use the debugger, just to learn what's going on, but probably you have some confusion about the concept. This can help you: Multidimensional Arrays — C++ Tutorials.

—SA


这篇关于五维数组?在c ++中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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