BCB中如何实现二维动态数组?
热门软件下载:
bcb中如何实现二维动态数组?
我想到了victor包容器, 可是只能用一组的数组, 如:
victor<float> vmydata;
可是如何实现动态的二维呢?请高手帮忙!
推荐阅读
int size=10;
double *tmp[100];
for (int i=0;i<size;i++)
tmp[i]=new double [size];
...............
for(int i=0;i<size;i++)
delete [] tmp[i];
用dynamicarray<dynamicarray<float>>
for example:
typedef dynamicarray<dynamicarray<float>> array_2;
array_2 array1;
array1.length=10;
for(int i=0;i<array1.length;i++)
{
array1[i].length=8;
for(int j=0;j<array1[i].length;j++)
array1[i][j]=i*j;
}
http://expert.csdn.net/expert/topic/1251/1251269.xml?temp=.7109949
victor<victor<float> > myarray;
注意第 2 个 victor<float> 后面有一个空格。
生成一维的,使用时,按照数组的存储方法进行操作~~
如:
new temp = new float[n*n];
使用时,用宏定义一个
#define atemp(i,j) temp[(i)*n+j]
^_^
其实,最好使用的是链表
tlist aalist;
使用vector时,可用如下方法
typedef vector<float> vf;
typedef vector< vector<float> > vf2;
vf2 vf2;
int dim1count=3,dim2count=5;
for(int i=0;i<dim1count;i++)
{
vf vf;
for(j=0;j<dim2count;j++)
vf.push_back((i+j)/2);
vf2.push_back(vf);
}
上面的程序生成了一个3*5的二维数组。
用vector生成多维数组不是很方便。
boost里好像有一个专门的多维数组的模板。
相关评论