Search code examples
c++visual-studio-2008programming-languagesvector

C++ 5 dimensional vector?


I am trying to make a 5 dimensional vector and I can’t seem to get it to work. I know if I need to write a 3 dimensional vector, I could write it in the following way: vector< vector< vector<string> > > block(27, vector< vector<string> > (27, vector<string>(27)));

Then I call it: block[x][y][z] = “hello”;

I wrote the 5 dimensional vector in the following way and it gives me error. vector< vector< vector< vector< vector<string> > > > > block(27, vector< vector< vector< vector<string> > > >(27, vector< vector< vector<string> > >(27, vector< vector<string> >(27, vector<string>(27)))));

Can you please tell me how to write a 5 dimensional vector in the right way? Thanks a lot.


Solution

  • But you should stop and think if a dictionary would work better. If the data is sparse you'll save a ton of memory. Create a key using the 5 dimensions, and create only the members you need.