Vector instead of array
1. Declare an int vector to replace the one-dimensional array: vector <int> A; (equal to declaring an int array a[], size is not specified, can be dynamically added to the inside of the delete).
2. Replace the two-dimensional array with vectors. In fact, just declare a one-dimensional array vector, and an array name actually represents its first address, so just declare a vector of the address, that is: vector <int *> A. Same as ideal vectors instead of three-dimensional arrays, vector <int**>a; above and so on.
Here is another method of vectors instead of two-dimensional arrays, which are very similar in usage and arrays.
3. How do I get the elements in a vector? Its usage and array:
For example:
Vector <int *> A
int b = 5;
A.push_back (b);//The function is detailed below
cout<<a[0]; Output is 5
4. Usage
1.push_back add a data at the end of the array
2.pop_back remove the last data from the array
3.at get the data of the numbered position
4.begin get pointer to array header
5.end gets the pointer to the last cell +1 of the array
6. Front getting a reference to the array header
7.back get a reference to the last cell of the array
8.max_size get vector max can be how big
9.capacity the size of the current vector allocation
10.size size of current usage data
11.resize changes the current size of the data used, if it is larger than the current use, the default value is populated
12.reserve changes the size of the space allocated by the current VECOTR
13.erase Delete the data item that the pointer points to
14.clear empty the current vector
15.rbegin returns the starting pointer after the vector reversal (actually the original end-1)
16.rend returns the end pointer of the vector reversal (actually the original begin-1)
17.empty determine if the vector is empty
18.swap exchanging data with another vector
Vector instead of array