Is 3 dimension array possible to work with the algorithm of stl?

test2 is fine, but test wouldn't work
Do I have any way to make it work?
Thanks a lot

1
2
3
4
5
6
7
8
9
int test2[2][2] = { {0, 1}, {2, 3} };
  std::copy(test2[0], test2[0] + 4, std::ostream_iterator<int>(cout, ", "));
  cout<<endl;
  
  int test[2][2][2] = { {{0, 1}, {2, 3}},
                        {{4, 5}, {6, 7}}
                      };
  std::copy(test[0], test[0] + 8, std::ostream_iterator<int>(cout, ", "));
  cout<<endl;
What exactly do you want it to do, other than run without crashing?
1
2
3
4
5
  
int test[2][2][2] = { {{0, 1}, {2, 3}},
                        {{4, 5}, {6, 7}}
                      };
std::copy(test[0][0], test[0][0] + 8, std::ostream_iterator<int>(cout, ", "));
hi stereoMatching ,
in array test,sizeof(test[0]) is 16, so test[0]+n means the test[0]'s address with n*16,instead of test[0]'s address add n*8.

you can use test[0][0]+8 to repleace test[0]+8.

good luck!
All of the above shows that the stl alogorithms like copy only work with 1 dimensional arrays.
Thanks for all of you
but how about 3 dimension vector?
1
2
3
4
5
6
7
8
9
10
11
typedef std::vector<int> Int1D;
  typedef std::vector<Int1D> Int2D;
  typedef std::vector<Int2D> Int3D;

  Int2D twoDim(2, Int1D(2, 5));
  Int2D::const_iterator it2D;
  Int1D::const_iterator it1D;
  for(it2D = twoDim.begin(); it2D != twoDim.end(); ++it2D)
    for(it1D = (*it2D).begin(); it1D != (*it2D).end(); ++it1D)
      cout<<*it1D<<", ";
  cout<<endl;


I could iterate the contents like that, but it is a little bit verbose
do I have another choices?
Thanks a lot
All of the above shows that the stl alogorithms like copy only work with 1 dimensional arrays.


Even for some language that provide n-dimensional constructs, their underlying implementation could also be 1D too. It is just that the developer write code in a seemingly 2D, 3D syntax and assume it is good.

I believe down to the lowest level, 2D array is just a 1D array representation in memory isn't it ? Can someone doing compiler development explain to me ?

Thanks.
Topic archived. No new replies allowed.