(1) must contain the header file before using the vector <vector>: #include <vector> (2) Namespace std{template <class T, class A Llocator = allocator<t> > class vector; }vector elements can be of any type T, but must have assignable and copyable two properties. The second template parameter is optional to define the memory model, and the default model is the allocator provided by the C + + standard library. (3) When attaching or removing elements at the end, the vector performs fairly well. However, if you place or delete elements in the front or center, performance is not very good, because each element after the operation point must be moved to another location, And every move has to be called the assignment operator (4) One of the cheats for vector performance is to configure more memory than is needed for the elements it holds. When the memory applied by the vector is exhausted, the vector will reapply for a new memory, Typically, the newly requested memory will be twice times the original memory. Once the memory is reconfigured, all references,pointers,iterators associated with the vector element will fail (5) The operation of the vector:vector<elem> C Produces an empty vectorvector<elem> C1 (C2) produces a copy of another vector of the same type vector<elem> C (n) uses the element's default constructor to generate a vectorvect of size n Or<elem> c (n, Elem) produces a vector of size n, each of which is elemvector<elem> C (beg, end) to produce a vector with an interval [beg, end) as an element Initial value c.~vector<elem> () destroys all elements and frees memory C.size () returns the current number of elements C.empty () determines whether the vector is empty c.max_size () returns the maximum number of elements that can be accommodated C.capacity () returns the maximum number of elements that can be accommodated before reallocating space C.reserve () ifInsufficient, enlarged C1 Compare C2 compare can be ==,!=,<,>,<= and >=c1 = C2 Assign C2 all elements to C1c.assign (n, elem) copy n Elem, assign to Cc.assign (Beg, end) assigns the element within the interval [beg, end) to Cc1.swap (C2) to interchange C1 and C2 elements c.at (IDX) to return the element indicated by the index IDX, if the IDX is out of bounds and throws Out_of_ran GE exception C[idx] Returns the element indicated by the index IDX, does not perform a range check C.front () returns the first element, does not check whether the element exists C.back () returns the last element, does not check whether the element exists C.begin () returns a random The access iterator, which points to the first element C.end () returns a random access iterator that points to the next position of the last element C.rbegin () returns a reverse iterator that points to the first element of the reverse iteration c.rend () returns a reverse iterator that points to the last element of the reverse iteration The next position of the vector iterator continues to be effective unless there are two situations: (1) The user places or removes elements (2) in a smaller index position, resulting in memory reallocation due to changes in capacity C.insert (it, elem) Inserts a elem copy in the IT location and returns the location of the new element C.insert (it, N, elem) inserts n elem copies in it location, no return value C.insert (it, beg, end) in the IT location insert interval [Beg, end] within Copy of all elements, no return value C.push_back (elem) adds a elem copy at the end C.pop_back () removes the last element (but does not return) C.erase (IT) removes the element on the IT location, returning the position of the next element c.er The ASE (Beg, end) removes all elements in the [Beg, end] interval, returns the position of the next element c.resize (num) Changes the number of elements to num (if size () becomes larger, the new element that comes out will need to be constructed with the default constructor) C.re Size (num, elem) changes the number of elements to num (if size () becomes larger, the extraThe new element is a copy of the Elem) C.clear () empties the container
Vector Summary in STL