c++ standard library (vector)

A container in c++
It can store various types of objects like a container. Simply put, vector is a dynamic array that can store any type, and can increase and compress data.
Example: vector<int>test;
//Create a vector, int is the data type of the array element, test is the dynamic array name.

basic operation function

(1) Header file #include<vector>.
(2) Create vector object, vector<int> vec;
(3) Insert numbers at the end: vec.push_back(a);
(4) Use subscript to access elements, cout<< vec[0]<<endl;
(5) Insert element: vec.insert(vec.begin()+i,a); Insert a before the i+1th element; (
6) Delete element: vec.erase( vec.begin()+2); delete the third element
vec.erase(vec.begin()+i, vec.end()+j); delete the interval [i, j-1]; the interval starts from 0
( 7) Vector size: vec.size();
(8) Empty: vec.clear();

Guess you like

Origin blog.csdn.net/Barry_kk/article/details/121423267