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

  • 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
主站蜘蛛池模板: 沂南县| 祁门县| 凤凰县| 阿城市| 林口县| 阿坝县| 龙岩市| 太原市| 迁西县| 白朗县| 金阳县| 漳平市| 东平县| 沽源县| 巩义市| 大连市| 贵德县| 尼勒克县| 扶风县| 县级市| 漳浦县| 香格里拉县| 菏泽市| 顺昌县| 诏安县| 荥阳市| 宁国市| 正定县| 光山县| 江北区| 松原市| 公安县| 宾川县| 台南县| 克拉玛依市| 广西| 怀来县| 岫岩| 嘉禾县| 高唐县| 德化县|