- 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
推薦閱讀
- 少兒人工智能趣味入門:Scratch 3.0動畫與游戲編程
- 數據庫系統教程(第2版)
- Learning Bayesian Models with R
- x86匯編語言:從實模式到保護模式(第2版)
- Nginx Essentials
- Interactive Applications Using Matplotlib
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Learning Unreal Engine Android Game Development
- C專家編程
- C陷阱與缺陷
- Backbone.js Testing
- Learning Ionic(Second Edition)
- 軟件再工程:優化現有軟件系統的方法與最佳實踐
- Testing Practitioner Handbook
- 高性能Java架構:核心原理與案例實戰