#include <iostream>
#include <array>
int main()
{
// 創建一個包含5個整數的固定大小的陣列
std::array<int, 5> arr = { 1, 2, 3, 4, 5 };
// 使用範圍for循環遍歷陣列並打印每個元素
for (int x : arr) {
std::cout << x << " ";
}
std::cout << std::endl;
// size()
std::cout << "array size:" << arr.size() << std::endl;
// at()
std::cout << "element at index 4:" << arr.at(4) << std::endl;
// 使用正向迭代器遍歷陣列並打印每個元素
std::cout << "Forward traversal:" << std::endl;
for (auto it = arr.begin(); it != arr.end(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
// 使用反向迭代器遍歷陣列並打印每個元素
std::cout << "Reverse traversal:" << std::endl;
for (auto it = arr.rbegin(); it != arr.rend(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
// fill()
arr.fill(0);
// 打印 fill 之後的結果
std::cout << "after fill(0)" << std::endl;
for (auto it = arr.begin(); it != arr.end(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
return 0;
}