কম্পিউটার

একটি নির্দিষ্ট মান সহ একটি C++ STL ভেক্টর থেকে কীভাবে একটি আইটেম সরাতে হয়?


একটি নির্দিষ্ট মান সহ একটি C++ STL ভেক্টর থেকে একটি আইটেম সরাতে ইরেজ ফাংশন ব্যবহার করা হয়।

অ্যালগরিদম

Begin
Declare vector v and iterator it to the vector.
Initialize the vector.
Erase() function is used to remove item from end.
Print the remaining elements.
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-এ ভেক্টর সন্নিবেশ() ফাংশন

  3. কিভাবে C++ একটি স্ট্রিং থেকে নির্দিষ্ট অক্ষর মুছে ফেলা যায়?

  4. কিভাবে C# এ একটি ArrayList থেকে একটি আইটেম সরাতে হয়?