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

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
主站蜘蛛池模板: 永靖县| 佛教| 延边| 怀集县| 肥乡县| 烟台市| 岑溪市| 韶山市| 凤冈县| 临夏县| 体育| 黄大仙区| 鸡东县| 玉田县| 芦溪县| 竹北市| 武功县| 台东县| 六安市| 葫芦岛市| 兴化市| 绩溪县| 施秉县| 湟源县| 韶关市| 罗山县| 白城市| 沅江市| 拉萨市| 元江| 宝鸡市| 南京市| 靖安县| 吴桥县| 镶黄旗| 贵南县| 宜阳县| 景东| 义乌市| 弋阳县| 丰顺县|