
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Removing an element from C++ std::vector<> by index?
Remove an element from C++ std::vector<> by index can be done by following way −
Example
#include<iostream> #include<vector> using namespace std; int main() { vector<int> v; //declare vector //insert elements into vector v.push_back(-10); v.push_back(7); v.push_back(6); // Deletes the first element (v[0]) v.erase(v.begin() ); for (int i = 0; i < v.size(); i++) cout << v[i] << " "; }
Output
7 6
- Related Articles
- std::vector::resize() vs. std::vector::reserve() in C++
- Removing an element from an Array in Javascript
- Removing an array element from a MongoDB collection
- Difference between std::vector and std::array in C++
- How to remove an element from a list by index in Python?
- Replace an element at a specified index of the Vector in Java
- How to find the index of an element in a vector in R?
- Removing _id element from PyMongo results?
- Removing the Min Element from Deaps
- Get an element from a Stack in Java without removing it
- Removing an element from the end of the array in Javascript
- Removing an element from the start of the array in javascript
- Removing an array element from MongoDB collection using update() and $pull
- Removing the Min Element from Interval Heaps
- Removing an element from a given position of the array in Javascript

Advertisements