![]() |
In C++, vectors are the same as arrays but they can resize themselves automatically when required as their storage is handled automatically by the container. In this article, we will learn how to remove a specific element from a vector in C++ Example: Input: Erase a Specific Element from a Vector in C++In C++, the std::vector class template provides a member function std::vector::erase() which can be used to remove a specific element from a vector. The erase function accepts the position of the element to be removed and then removes that element from the vector. We can find the position of the specific element we want to remove using the std::find method. C++ Program to Erase a Specific Element from a VectorC++
Output
Vector Before Deletion:1 2 3 4 5 6 7 8 Vector After Deletion:1 2 3 4 6 7 8 Time Complexity: O(N), where N is the total number of elements present in the vector |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |