fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main(){
  5.  
  6. std::vector < std::vector<std::vector<int>>> vec3d;
  7. //static const int N = 4;
  8. vec3d.resize(2);
  9. for (std::size_t i = 0; i < vec3d.size(); i++){
  10. vec3d[i].resize(3);
  11. for (std::size_t j = 0; j < vec3d[i].size(); j++){
  12. vec3d[i][j].resize(4);
  13. }
  14.  
  15. }
  16.  
  17. int i = 0;
  18. for (auto&ooo : vec3d){
  19. for (auto& oo : ooo){
  20. for (auto& o : oo) o = i++;
  21. }
  22. }
  23.  
  24. for (auto&ooo : vec3d){
  25. std::cout << '['<<std::endl;
  26. for (auto& oo : ooo){
  27. std::cout << '[';
  28. for (auto& o : oo) std::cout << o << ',';
  29. std::cout << ']'<<std::endl;
  30. }
  31. std::cout << ']'<<std::endl;
  32. }
  33.  
  34. std::cout<<vec3d[1][2][3];
  35.  
  36. return 0;
  37.  
  38. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
[
[0,1,2,3,]
[4,5,6,7,]
[8,9,10,11,]
]
[
[12,13,14,15,]
[16,17,18,19,]
[20,21,22,23,]
]
23