fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main(int argc, const char * argv[])
  10. {
  11. int n = 5;
  12.  
  13. vector<int> p1_flat;
  14. for(int i = 0; i < n*n; ++i) p1_flat.push_back(i);
  15.  
  16. vector<vector<int>> p1(n,vector<int>(n));
  17.  
  18. for(int i = 0; i < n; ++i)
  19. copy_n(p1_flat.begin()+i*n,n,p1[i].begin());
  20.  
  21. for(auto a: p1)
  22. {
  23. for(auto b: a) cout << setw(2) << b << " ";
  24. cout << endl;
  25. }
  26.  
  27.  
  28. }
  29.  
Success #stdin #stdout 0s 4396KB
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 24