- 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
推薦閱讀
- 高手是如何做產(chǎn)品設(shè)計的(全2冊)
- Java程序設(shè)計實戰(zhàn)教程
- GraphQL學(xué)習(xí)指南
- C#編程入門指南(上下冊)
- 數(shù)據(jù)結(jié)構(gòu)簡明教程(第2版)微課版
- Interactive Applications Using Matplotlib
- 人人都是網(wǎng)站分析師:從分析師的視角理解網(wǎng)站和解讀數(shù)據(jù)
- C#程序設(shè)計
- 深入淺出Serverless:技術(shù)原理與應(yīng)用實踐
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Lighttpd源碼分析
- 用戶體驗可視化指南
- Swift 4 Protocol-Oriented Programming(Third Edition)
- 基于ARM Cortex-M4F內(nèi)核的MSP432 MCU開發(fā)實踐
- Java Web應(yīng)用開發(fā)項目教程