fork(2) download
  1. #include <iostream>
  2.  
  3.  
  4. // Print a single element (use in array version)
  5. template<typename T>
  6. void printArray(T const &e, std::ostream& out = std::cout )
  7. {
  8. out << e;
  9. }
  10.  
  11. // Print an (nested) array
  12. template<typename T1, size_t arrSize>
  13. void printArray(T1 const(& arr)[arrSize], std::ostream& out = std::cout )
  14. {
  15. out << "[";
  16. if ( arrSize )
  17. {
  18. const char* sep = "";
  19. for (const auto& e : arr)
  20. {
  21. out << sep;
  22. printArray(e, out);
  23. sep = ", ";
  24. }
  25. }
  26. out << "]";
  27. }
  28.  
  29. int arr[5][5];
  30.  
  31. int main()
  32. {
  33. printArray( arr[0] );
  34. std::cout << std::endl;
  35. printArray( arr );
  36. }
  37.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
[0, 0, 0, 0, 0]
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]