c++ clear vector code example
Example 1: delete from front in vector c++
vector_name.erase(vector_name.begin());
vector_name.erase(vector_name.begin()+(x-1));
vector_name.pop_back();
Example 2: clear vs erase vector c++
vectorname.clear()
vectorname.erase(startingposition, endingposition)
clear() removes all the elements from a vector container, thus making its
size 0. All the elements of the vector are removed using clear() function.
erase() function, on the other hand, is used to remove specific elements from
the container or a range of elements from the container, thus reducing its
size by the number of elements removed.
Example 3: C++ Vector clear syntax
vector<T>().swap(x);