fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<typename T>
  5. std::vector<std::vector<T>> vvalloc(const int rows, const int cols){
  6. return std::vector<std::vector<T>>(rows, std::vector<T>(cols));
  7. }
  8.  
  9. template<typename T>
  10. void vvprint(const std::vector<std::vector<T>>& rhs){
  11. for(int p=0; p<rhs.size(); p++){
  12. std::cout << "[ ";
  13. for(int q=0; q<rhs[p].size(); q++){
  14. std::cout << rhs[p][q] << ' ';
  15. }
  16. std::cout << "]" << std::endl;
  17. }
  18. }
  19.  
  20. int main(){
  21. std::vector<std::vector<int>> vvec = vvalloc<int>(3, 3);
  22.  
  23. int i=0;
  24. for(int p=0; p<vvec.size(); p++){
  25. for(int q=0; q<vvec[p].size(); q++){
  26. vvec[p][q] = i++;
  27. }
  28. }
  29.  
  30. vvprint<int>(vvec);
  31. return 0;
  32. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
[ 0 1 2 ]
[ 3 4 5 ]
[ 6 7 8 ]