Syntax: vector<type>vector_name;
Example: vector<int>v;
Some useful member functions of vectors
- push_back(): This function add a new element at the end of vector after its current last element.
- pop_back(): This function removes the last element from the vector.
- begin(): It returns a iterator pointing to the first element of the vector.
- end(): It returns a iterator pointing to the last elements of the vector.
- size(): This function returns the size(number of elements) of the vector.
- clear(): It removes all the elements of the vector, making it empty with size 0.
C++ program to implement vectors using STL
Output