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

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
主站蜘蛛池模板: 富源县| 华宁县| 铁力市| 彝良县| 蓬安县| 白河县| 上虞市| 民权县| 珲春市| 沅江市| 谢通门县| 且末县| 乌兰浩特市| 那曲县| 久治县| 甘肃省| 田林县| 永定县| 水富县| 萍乡市| 通许县| 琼中| 密山市| 吴忠市| 安平县| 司法| 镇远县| 上杭县| 开封市| 沐川县| 竹北市| 田阳县| 曲周县| 德兴市| 哈尔滨市| 绥阳县| 新巴尔虎右旗| 句容市| 合江县| 峨眉山市| 两当县|