// Deletes the first element from vector v
v.erase(v.begin());
// 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();
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> nums;
nums.push_back(6);
nums.push_back(2);
nums.push_back(7);
nums.push_back(1);
nums.erase(nums.begin());
for (int num: nums)
cout << num << endl;
}
Code Example |
---|
Cpp :: continue c++ |
Cpp :: 2-Dimensional array in c++ |
Cpp :: how to get size of 2d vector in c++ |
Cpp :: c++ splitstring example |
Cpp :: detect end of user input cpp |
Cpp :: set clear c++ |
Cpp :: how to find the sum of a vector c++ |
Cpp :: checking if a string has only letters cpp |
Cpp :: c++ pi float |
Cpp :: cudamemcpy |
Cpp :: loop through array c++ |
Cpp :: find prime number c++ |
Cpp :: C++ break with for loop |
Cpp :: long to string cpp |
Cpp :: inline function in c++ |
Cpp :: pointer in return function c++ |
Cpp :: cpp print variable value |
Cpp :: check prime cpp gfg |
Cpp :: how to split string into words c++ |
Cpp :: find element in vector |
Cpp :: insertion sort cpp |
Cpp :: dynamic allocation c++ |
Cpp :: set to vector |
Cpp :: c++ finding gcd |
Cpp :: vector iterating |
Cpp :: C++ String Compare Example |
Cpp :: cpp get exception type |
Cpp :: exponent of x using c c++ |
Cpp :: how to take full sentence in c++ |
Cpp :: how to access a vector member by its index |