কম্পিউটার টিউটোরিয়াল

C++ STL ভেক্টর থেকে নির্দিষ্ট ভ্যালুর আইটেম রিমুভ করা: erase() ফাংশন

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
  1. C++ STL asinh() ফাংশন

  2. C++ STL-এ vector::insert() ফাংশন

  3. C++-এ স্ট্রিং থেকে নির্দিষ্ট ক্যারেক্টার রিমুভ করা: erase() এবং remove()

  4. C#-এ ArrayList-এ서 আইটেম সরানো (Remove মেথড)