1#include <iostream>
2#include <array>
3using namespace std;
4
5int main () {
6 const int size = 5;
7 array<int, size> numbers; // create stl array template
8 array<int, size> :: iterator NUMBER_ITERATOR; // declare iterator that points to stl template numbahs
9
10 NUMBER_ITERATOR = numbers.begin(); // points iterator to first element in array template
11 cout << "Please fill the array: \n";
12 for(;NUMBER_ITERATOR != numbers.end(); NUMBER_ITERATOR++) cin >> *NUMBER_ITERATOR; // enter the value for each element one-by-one
13
14 NUMBER_ITERATOR = numbers.begin(); // reset the pointer to first element
15 cout << "Displaying array: \n";
16 for(;NUMBER_ITERATOR != numbers.end(); NUMBER_ITERATOR++) cout << *NUMBER_ITERATOR << "\n"; // prints out value for each
17 cout << endl;
18
19 return 0;
20}
1#include <bits/stdc++.h>
2using namespace std;
3
4main() {
5 array<string, 3> a1{"a", "b", "c"};
6 array<int, 5> a2;
7 cout<<a1[0]<<endl;
8 //size of array
9 cout<<a1.size()<<endl;
10 //Sorts the elements
11 sort(a1.begin(), a1.end());
12 for(auto& i: a1) {
13 cout << i << ' ';
14 }
15}