C++ STL ভেক্টর থেকে নির্দিষ্ট ভ্যালুর আইটেম রিমুভ করতে erase() ফাংশন ব্যবহার করা হয়।
অ্যালগরিদম
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