Iterating through the array
suggest changeBecause std::array is a standard-library container, it can be traversed with a range-based for loop just like std::vector and other containers. Class template argument deduction in the sample is C++17; earlier dialects spell the element type and the size.
#include <array>
#include <iostream>
int main() {
std::array values{1, 2, 3};
for (int value : values) {
std::cout << value << '\n';
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents