Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

remove element from vector



// 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: #remove #element #vector
ADD COMMENT
Topic
Name
5+5 =