fork download
  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4.  
  5. void printInt5Array(const array<int, 5> &arr) {
  6. for (auto item : arr) {
  7. cout << item << " | ";
  8. }
  9. }
  10.  
  11. template<class T, size_t S>
  12. void printArray(const array<T, S> &arr) {
  13. for (auto item : arr) {
  14. cout << item << " | ";
  15. }
  16. }
  17.  
  18. int main() {
  19. array<int, 5> a = { 1, 2, 3, 4, 5};
  20.  
  21. ::printInt5Array(a);
  22. cout << endl;
  23.  
  24.  
  25. ::printArray(a);
  26. cout << endl;
  27.  
  28. array<double, 3> b = { 1.2, 2.3, 3.4 };
  29.  
  30. ::printArray(b);
  31. cout << endl;
  32.  
  33. array<char, 5> hello = { 'H','e','l','l','o', };
  34.  
  35. ::printArray(hello);
  36. cout << endl;
  37. }
Success #stdin #stdout 0s 4304KB
stdin
Standard input is empty
stdout
1 | 2 | 3 | 4 | 5 | 
1 | 2 | 3 | 4 | 5 | 
1.2 | 2.3 | 3.4 | 
H | e | l | l | o |