Array get() function in C++ STL?

C++Server Side ProgrammingProgramming

In this section we will see the get() function of array in C++ STL. This function is used to get the ith element of the array container. The syntax is like below −


get<i> array_name

This function takes two mandatory parameters. The is the index parameter. It is used to point to the ith position of the array. The second argument is array_name. This is the actual array from this ith element will be taken. This function returns the ith element.

Let us see one example to get the idea.


 Live Demo

using namespace std;
main() {
   array<int, 10> arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99};
   cout << "1st element: " << get<0>(arr) << endl;
   cout << "6th element: " << get<5>(arr) << endl;
   cout << "8th element: " << get<7>(arr) << endl;
   cout << "10th element: " << get<9>(arr) << endl;


1st element: 0
6th element: 55
8th element: 77
10th element: 99
Published on 26-Jul-2019 14:34:36