Erase फंक्शन का उपयोग C++ STL वेक्टर से किसी निश्चित मान वाले आइटम को हटाने के लिए किया जाता है।
एल्गोरिदम
Begin
वेक्टर v और वेक्टर के लिए इटरेटर it घोषित करें।
वेक्टर आरंभ करें।
Erase() फंक्शन का उपयोग अंत से आइटम हटाने के लिए किया जाता है।
शेष एलिमेंट्स प्रिंट करें।
End.
उदाहरण कोड
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v{ 6,7,8,9,10};
vector<int>::iterator it;
it = v.end();
it--;
v.erase(it);
for (auto it = v.begin(); it != v.end(); ++it)
cout << ' ' << *it;
return 0;
}
आउटपुट
The current content of the vector is : 6 7 8 9 10
Please enter the element to be deleted -> 7
The current content of the vector is : 6 8 9 10