std array c++ code example
Example 1: array template c++
#include <iostream>
#include <array>
using namespace std;
int main () {
const int size = 5;
array<int, size> numbers;
array<int, size> :: iterator NUMBER_ITERATOR;
NUMBER_ITERATOR = numbers.begin();
cout << "Please fill the array: \n";
for(;NUMBER_ITERATOR != numbers.end(); NUMBER_ITERATOR++) cin >> *NUMBER_ITERATOR;
NUMBER_ITERATOR = numbers.begin();
cout << "Displaying array: \n";
for(;NUMBER_ITERATOR != numbers.end(); NUMBER_ITERATOR++) cout << *NUMBER_ITERATOR << "\n";
cout << endl;
return 0;
}
Example 2: std array c++
#include <bits/stdc++.h>
using namespace std;
main() {
array<string, 3> a1{"a", "b", "c"};
array<int, 5> a2;
cout<<a1[0]<<endl;
cout<<a1.size()<<endl;
sort(a1.begin(), a1.end());
for(auto& i: a1) {
cout << i << ' ';
}
}