1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <array>
int main() {
// Create a std::array of 5 integers
std::array<int, 5> myArray = {1, 2, 3, 4, 5};
// Access elements using the index operator
std::cout << "First element: " << myArray[0] << std::endl;
std::cout << "Second element: " << myArray[1] << std::endl;
// Iterate over the array using a range-based for loop
std::cout << "Elements: ";
for (int value : myArray) {
std::cout << value << " ";
}
std::cout << std::endl;
return 0;
}
Back to std_array