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

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
主站蜘蛛池模板: 禄劝| 安平县| 辽中县| 新晃| 左权县| 黄冈市| 东兰县| 杭锦后旗| 滨州市| 思茅市| 呼和浩特市| 临颍县| 上栗县| 临清市| 宣武区| 临清市| 安新县| 汾西县| 临潭县| 县级市| 玛沁县| 壤塘县| 崇阳县| 彭水| 酒泉市| 大渡口区| 杭锦后旗| 洛宁县| 昂仁县| 南城县| 蕉岭县| 辛集市| 齐齐哈尔市| 泾川县| 南涧| 鸡西市| 石首市| 林口县| 雅江县| 马公市| 亳州市|