动态数组,简单问题,马上结分!!! 请问在VC中有没有二维和三维的动态数组,如果有,能给个用法示范一下吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int** pp=new int*[10];for(int i=0;i<10;++i) pp[i]=new int[8];这就是一个int[10][8]的动态数组 1. 演示形为int[2][3]的二维动态数组///////////////////////////////////////////////////////////////////int n1, n2;const int DIM1 = 2;const int DIM2 = 3;// 构造数组int **ppi = new int*[DIM1];for(n1 = 0; n1 < DIM1; n1++){ ppi[n1] = new int[DIM2];}// 填充数据for(n1 = 0; n1 < DIM1; n1++){ for(n2 = 0; n2 < DIM2; n2++) { ppi[n1][n2] = n1 * 10 + n2; }}// 输出for(n1 = 0; n1 < DIM1; n1++){ for(n2 = 0; n2 < DIM2; n2++) { afxDump << "ppi[" << n1 << "][" << n2 << "] = " << ppi[n1][n2] << "\n"; }}// 释放数组for(n1 = 0; n1 < DIM1; n1++){ delete [] ppi[n1];}delete [] ppi;2. 三维动态数组(int[2][3][4])///////////////////////////////////////////////////////////////////int n1, n2, n3;const int DIM1 = 2;const int DIM2 = 3;const int DIM3 = 4;// 构造数组int ***ppi = new int**[DIM1];for(n1 = 0; n1 < DIM1; n1++){ ppi[n1] = new int*[DIM2]; for(n2 = 0; n2 < DIM2; n2++) { ppi[n1][n2] = new int[DIM3]; }}// 填充数据for(n1 = 0; n1 < DIM1; n1++){ for(n2 = 0; n2 < DIM2; n2++) { for(n3 = 0; n3 < DIM3; n3++) { ppi[n1][n2][n3] = n1 * 100 + n2 * 10 + n3; } }}// 输出for(n1 = 0; n1 < DIM1; n1++){ for(n2 = 0; n2 < DIM2; n2++) { for(n3 = 0; n3 < DIM3; n3++) { afxDump << "ppi[" << n1 << "][" << n2 << "][" << n3 << "] = " << ppi[n1][n2][n3] << "\n"; } }}// 释放数组for(n1 = 0; n1 < DIM1; n1++){ for(n2 = 0; n2 < DIM2; n2++) { delete [] ppi[n1][n2]; } delete [] ppi[n1];}delete [] ppi; 不能,for(n1 = 0; n1 < DIM1; n1++){ ppi[n1] = new int*[DIM2];你说,怎么保证 ppi[0]和ppi[1]挨着? 请教大侠:如何判断菜单是否在弹出状态? mfc中如何对一个圆形区域进行重绘? ffmpeg结构体的使用问题(windows下),等待高手 高分求:C++调用C#写的WebService函数,参数无法传递 解决的方法 vc 的网络编程问题 请问怎么样才能将_RecordsetPtr和datagrid 绑定起来? 一个文件列表的简单问题? 把bitmap写到文件中去! 谁能告诉我,怎样才能让自己的程序自动把自己传给对方的服务器,并在一定事件的激发下被激活,象尼姆达那样 采用重叠I/O模式之事件通知中遇到的问题? 滚动条的设置问题 unicode显示的问题,急!!!!!
for(int i=0;i<10;++i)
pp[i]=new int[8];
这就是一个int[10][8]的动态数组
///////////////////////////////////////////////////////////////////
int n1, n2;const int DIM1 = 2;
const int DIM2 = 3;// 构造数组
int **ppi = new int*[DIM1];
for(n1 = 0; n1 < DIM1; n1++)
{
ppi[n1] = new int[DIM2];
}// 填充数据
for(n1 = 0; n1 < DIM1; n1++)
{
for(n2 = 0; n2 < DIM2; n2++)
{
ppi[n1][n2] = n1 * 10 + n2;
}
}// 输出
for(n1 = 0; n1 < DIM1; n1++)
{
for(n2 = 0; n2 < DIM2; n2++)
{
afxDump << "ppi[" << n1 << "][" << n2 << "] = "
<< ppi[n1][n2] << "\n";
}
}// 释放数组
for(n1 = 0; n1 < DIM1; n1++)
{
delete [] ppi[n1];
}
delete [] ppi;
2. 三维动态数组(int[2][3][4])
///////////////////////////////////////////////////////////////////int n1, n2, n3;const int DIM1 = 2;
const int DIM2 = 3;
const int DIM3 = 4;// 构造数组
int ***ppi = new int**[DIM1];
for(n1 = 0; n1 < DIM1; n1++)
{
ppi[n1] = new int*[DIM2];
for(n2 = 0; n2 < DIM2; n2++)
{
ppi[n1][n2] = new int[DIM3];
}
}// 填充数据
for(n1 = 0; n1 < DIM1; n1++)
{
for(n2 = 0; n2 < DIM2; n2++)
{
for(n3 = 0; n3 < DIM3; n3++)
{
ppi[n1][n2][n3] = n1 * 100 + n2 * 10 + n3;
}
}
}// 输出
for(n1 = 0; n1 < DIM1; n1++)
{
for(n2 = 0; n2 < DIM2; n2++)
{
for(n3 = 0; n3 < DIM3; n3++)
{
afxDump << "ppi[" << n1 << "][" << n2 << "][" << n3 << "] = "
<< ppi[n1][n2][n3] << "\n";
}
}
}// 释放数组
for(n1 = 0; n1 < DIM1; n1++)
{
for(n2 = 0; n2 < DIM2; n2++)
{
delete [] ppi[n1][n2];
}
delete [] ppi[n1];
}
delete [] ppi;
for(n1 = 0; n1 < DIM1; n1++)
{
ppi[n1] = new int*[DIM2];你说,怎么保证 ppi[0]和ppi[1]挨着?