C ++ STL中的数组get()函数?
在本节中,我们将看到get()C++STL中的数组功能。此函数用于获取数组容器的第ith个元素。语法如下-
语法
get<i> array_name
此功能有两个必填参数。是索引参数。它用于指向数组的第i个位置。第二个参数是array_name。这是第ith个元素的实际数组。此函数返回第ith个元素。
让我们看一个例子来了解这个想法。
示例
#include<iostream>
#include<array>
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
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短