官术网_书友最值得收藏!

Array

The STL array container is a fixed-size sequence container, just like a C/C++ built-in array, except that the STL array is size-aware and a bit smarter than the built-in C/C++ array. Let's understand an STL array with an example:

#include <iostream>
#include <array>
using namespace std;
int main () {
array<int,5> a = { 1, 5, 2, 4, 3 };

cout << "\nSize of array is " << a.size() << endl;

auto pos = a.begin();

cout << endl;
while ( pos != a.end() )
cout << *pos++ << "\t";
cout << endl;

return 0;
}

The preceding code can be compiled and the output can be viewed with the following commands:

g++ main.cpp -std=c++17
./a.out

The output of the program is as follows:

Size of array is 5
1 5 2 4 3
主站蜘蛛池模板: 浮山县| 泸西县| 广德县| 洪江市| 开封市| 榆树市| 和田市| 井研县| 上饶市| 岢岚县| 固原市| 新密市| 疏附县| 信丰县| 丰台区| 梅州市| 蛟河市| 弋阳县| 鲁甸县| 河北省| 界首市| 双鸭山市| 江川县| 阜宁县| 句容市| 丹棱县| 鄯善县| 台东县| 泰顺县| 彭山县| 温州市| 安国市| 吉林市| 香河县| 林芝县| 自治县| 高邮市| 平乡县| 彰化县| 楚雄市| 章丘市|