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

  • Mastering C++ Programming
  • Jeganathan Swaminathan
  • 133字
  • 2021-07-02 18:28:49

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
主站蜘蛛池模板: 长乐市| 瑞昌市| 治县。| 乌兰浩特市| 新河县| 甘南县| 朝阳市| 罗源县| 抚宁县| 舟曲县| 石屏县| 贡嘎县| 五华县| 合作市| 赣榆县| 曲松县| 江都市| 师宗县| 沙河市| 淳安县| 巧家县| 合肥市| 额尔古纳市| 普宁市| 稷山县| 隆林| 伊通| 陆河县| 旅游| 开封县| 吉水县| 大田县| 方山县| 宁陵县| 清涧县| 台前县| 铜鼓县| 呈贡县| 蒙山县| 探索| 财经|