1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <array>
#include <string>
template<typename T, size_t N>
void PrintArray(std::array<T, N> const&);
template <typename T, size_t N>
std::ostream& operator<<(std::ostream&, std::array<T, N> const&);
int main()
{
std::array<int, 5> a { 1, 2, 3, 4, 5 };
PrintArray(a);
std::array<double, 3> b { 6.1, 7.275, 8.3333333333 };
std::cout << b << '\n';
std::array<std::string, 4> c { "Test", "Word", "Hello", "Good-bye" };
std::cout << c << '\n';
}
template<typename T, size_t N>
void PrintArray(std::array<T, N> const& arr)
{
std::cout << "The array contains " << arr.size() << " elements\n";
for (const auto itr : arr)
{
std::cout << itr << ' ';
}
std::cout << "\n\n";
}
template <typename T, size_t N>
std::ostream& operator<<(std::ostream& os, std::array<T, N> const& arr)
{
os << "The array contains " << arr.size() << " elements.\n";
for (const auto itr : arr)
{
os << itr << ' ';
}
os << '\n';
return os;
}
|