fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <list>
  4. #include <vector>
  5.  
  6. template < typename SEQUENCE_2D >
  7. void print_seq2d( const SEQUENCE_2D& a, int width = 2 )
  8. {
  9. for( const auto& row : a )
  10. {
  11. for( const auto& v : row ) std::cout << std::setw(width) << v ;
  12. std::cout << '\n' ;
  13. }
  14. std::cout << "------------\n" ;
  15. }
  16.  
  17. int main()
  18. {
  19. int a[][3] = { { 1, 2, 3 }, { 3, 4, 5 }, { 5, 6, 7 }, { 8, 9, 1 } } ;
  20. short b[][4] = { { 35, 16, 7, 8 } , { 3, 29, 2, 42 }, { 21, 32, 43, 54 } } ;
  21. std::list< std::vector<long> > c = { { 1, 2, 3 }, { 3, 4 }, { 5 }, { 6, 7 }, { 5, 6, 7, 8 } } ;
  22.  
  23. print_seq2d(a) ;
  24. print_seq2d( b, 3 ) ;
  25. print_seq2d(c) ;
  26. }
  27.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
 1 2 3
 3 4 5
 5 6 7
 8 9 1
------------
 35 16  7  8
  3 29  2 42
 21 32 43 54
------------
 1 2 3
 3 4
 5
 6 7
 5 6 7 8
------------