Given that all necessary libraries are included and given th
Given that all necessary libraries are included and given the following declarations: vector vec;//code to fill vec with unique integers vector:: iterator itr; write the code to initialize vec with 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, then using iterator itr to remove 14 from the vector.
Solution
Please find below, the whole code.
The find algorithm first finds the value required and removes it.
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> vec={11,12,13,14,15,16,17,18,19,20}; //initialise the vector
vector<int>::iterator itr;
vec.erase(find(vec.begin(),vec.end(),14)); //the erase function is used to remove value / values from a vector.
//printing the vector.....these 2 line can be removed if needed.
for(itr=vec.begin();itr!=vec.end();itr++)
cout<<*itr<<endl;
}
