How to delete more than one element from an array in C++? -


i have question..how can delete more 1 elements 1 dimensional array in c++? suppose have array a={1,3,5,8,9,7} , want delete suppose 3,5,7 array a. please kindly let me know if knows efficient algorithm.

arrays not resizable in c++. best option resizable container std::vector use as:

    std::vector<int> v = {1,3,5,8,9,7}; 

and remove elements predicate:

   auto new_end = std::remove_if(v.begin(), v.end(),                                  std::bind(std::less<int>(), _1, 6)); 

but shuffles elements around vector @ end. erase them, need call:

   v.erase(new_end, v.end()); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -