#include#include int main() { std::array arr = {1, 2, 3, 4, 5}; std::cout << "arr size: " << arr.size() << '\n'; return 0; }
#include#include int main() { std::array arr = {1, 2, 3, 4, 5}; // Accessing array elements std::cout << "arr[0]: " << arr[0] << '\n'; // 1 std::cout << "arr[1]: " << arr[1] << '\n'; // 2 std::cout << "arr[2]: " << arr[2] << '\n'; // 3 std::cout << "arr[3]: " << arr.at(3) << '\n'; // 4 std::cout << "arr[4]: " << arr.back() << '\n'; // 5 return 0; }
#includeThis example shows how to iterate through an array using a for loop and a range-based for loop. In conclusion, std::array is a package library in C++ that provides a static array container which encapsulates arrays of fixed size. It is part of the standard library and requires no additional installation or linking.#include int main() { std::array arr = {1, 2, 3, 4, 5}; // Iterating through array using a for loop std::cout << "Array elements: "; for (int i=0; i < arr.size(); ++i) { std::cout << arr[i] << " "; } std::cout << '\n'; // Iterating through array using a range-based for loop std::cout << "Array elements: "; for (auto& elem : arr) { std::cout << elem << " "; } std::cout << '\n'; return 0; }