Vector vector originally meaning, but in the use of a similar length of the array is not limited.
Definition Syntax: Vector <data type> name;
First, the header file: <vector> (bits / stdc ++ please ignore)
Second, the commonly used methods:
a.size (); // read size
a.resize (): // resize
a.push_back (); // add elements to the tail
a.pop_back (); // remove the last element
a.clear (); // Clear
a.empty (): // returned is empty
Third, traversal
STL data type is almost (perhaps all) using an iterator to traverse.
vector <int> :: = a.begin IT Iterator (); // create a vector iterator type (similar pointer) pointing to a first address
Write for in that:
for (vector<int>::iterator it = a.begin(); it != a.end();it++)
* It can then be used to access the value of the address pointed.
Fourth, other
Insert elements: vec.insert (vec.begin () + i , a); a is inserted in front of the first element i + 1; (i.e. this is the location a i + 1) is
deleted elements: vec.erase (vec .begin () + 2); remove the third element
vec.erase (vec.begin () + i, vec.end () + j); delete interval [i, j-1]; interval from 0 (the controversy is relatively large, retained doubts, not normal)
To be added…………