Vulkan

C++ 动态二维数组

#include<iomanip>
#include <iostream>
using namespace std;
int main()
{	
        int wid,hei;
	cout<<"Input wid"<<endl;
	cin>>wid;
	cout<<"Input hei"<<endl;	
	cin>>hei;
	/***声明***/
	int **arra=new int *[hei];
	for (int i=0;i<hei;i++)
	{
		arra[i]=new int[wid];
	}
	/***赋值***/
	for(int j=0;j<hei;j++)
	{
		for (int k=0;k<wid;k++)
		{
			arra[j][k]=j*10+k;
		}
	}
	/***输出***/
	cout<<setw(5);
	for(int j=0;j<hei;j++)
	{
		for (int k=0;k<wid;k++)
		{
			cout<<arra[j][k]<<"   ";
		}
		cout<<endl;
	}
	/***释放内存***/
	for (int m=0;m<hei;m++)
	{
		delete [wid]arra[m];
		arra[m]=NULL;
	}
	delete [hei] arra;
	arra=NULL;

	return 0;
}

posted on 2012-09-04 14:32  Vulkan  阅读(176)  评论(0编辑  收藏  举报

导航