An array is added to the c++11 in place of the original C language.
At the same time, the use of dynamic array new and delete is avoided, and the memory is automatically managed.
Moreover, the execution efficiency is higher than the vector.
A definition
defined in the array header file:
template< class T, std::size_t N > struct array;
If we were to write an array template class ourselves, we would probably want to look like this:
Template <typename T, int n>class myarray{public : MyArray () {a = new t[n];} ~myarray () {delete[] A;} t& operator[] (int i) {return * (a+i);} Private: t* A;};
21-D Arrays
1 statement
Array<int, 5> arr1 = {1, 2, 3, 4, 5};
Or
Array<int, 5> arr1{{1, 2, 3, 4, 5}};
2 Visits
For example: Take the first element of an array
3 traversal
for (size_t i = 0; i < arr1.size (); ++i) {cout << arr1[0]<< endl;//cout << arr1.at (0) << Endl;}
32-D Arrays
1 statement
Array<array<int, 3>, 2> arr2d = {11,12,13,21,22,23};
2 Visits
For example: Or take the first element
int n3 = arr2d[0][0];
3 traversal
for (size_t i = 0; i < arr2d.size (), ++i) {for (size_t j= 0; J < arr2d[i].size (); ++j) {cout << arr2d[i][j] <&l T ' \ t ';} cout << Endl;}
As you can see, a two-bit array is actually a one-dimensional array whose elements are two-bit arrays
The principle and use of the c++11 array