I'm implementing an translating a Python
code to C++
, however I want to place a Multidimensional array at another Multidimensional array index. The values of first array should be copied to specific index of other 2D array.
Here's my Python Code:
var2 = "121"
a = [None for x in xrange(3)]
a[0] = [3,4,5],[6,4,7]
a[1] = [3,9,6],[7,8,7]
a[2] = [4,8,7],[7,6,7]
for x in var2:
print 'Value:',x,'\t'
Here's my C++ Code:
int a1[2][3] = {
{3,4,5},
{6,4,7}
};
int a2[2][3] = {
{3,9,6},
{7,8,7}
};
int a3[2][3] = {
{4,8,7},
{7,6,7}
};
Now I have an array:
int a[3][];
I want to copy a1 to a[0][0]
as in my python code.
My Question is, How can I copy a1,a2,a3 in array a such that:
a[0][0] = a1;
a[1][1] = a2;
a[2][2] = a3;
Also, the respective for-loop
for an array index.
One way to directly initialize the array to hold the data is :
int a[3][2][3] = {
{{3,4,5},
{6,4,7},},
{{3,9,6},
{7,8,7},},
{{4,8,7},
{7,6,7}}
};
for( int i=0; i<3; i++ ){
for( int j=0; j<2; j++ ){
for( int k=0; k<3; k++ ){
cout<<a[i][j][k]<<'\t';
}
cout<<endl;
}
cout<<endl<<endl;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.