- 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
推薦閱讀
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- Google Flutter Mobile Development Quick Start Guide
- Mastering Julia
- C語言從入門到精通(第4版)
- jQuery開發基礎教程
- Reactive Android Programming
- Getting Started with Gulp
- Building RESTful Python Web Services
- Java程序員面試筆試寶典(第2版)
- Flowable流程引擎實戰
- 深入實踐Kotlin元編程
- Cocos2d-x Game Development Blueprints
- Scratch從入門到精通
- Python高性能編程(第2版)
- 基于JavaScript的WebGIS開發