Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

erase element from vector c++



// erase element from vector by its index
    vector<string> strs {"first", "second", "third", "last"};
      
    string element = "third"; // the element which will be erased
    for(int i=0;i<strs.size();i++)
    {
      if(strs[i] == element)
      strs.erase(strs.begin()+i);
    }
    
Source by iq.opengenus.org #
 
PREVIOUS NEXT
Tagged: #erase #element #vector
ADD COMMENT
Topic
Name
1+7 =