how to erase first element of vector code example

Example 1: c++ vector pop first element

std::vector<int> vect;

vect.erase(vect.begin());

Example 2: delete from front in vector c++

// Deleting first element
vector_name.erase(vector_name.begin());

// Deleting xth element from start
vector_name.erase(vector_name.begin()+(x-1));

// Deleting from the last
vector_name.pop_back();

Example 3: remove first element from vector c++

// Deletes the first element from vector v
v.erase(v.begin());

Tags:

Cpp Example