How about std::remove()
instead:
#include <algorithm>
...
vec.erase(std::remove(vec.begin(), vec.end(), 8), vec.end());
This combination is also known as the erase-remove idiom.
More Related Contents:
- Erasing elements from a vector
- How do I erase an element from std::vector by index?
- Why can’t I make a vector of references?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- Alternative to vector
- Why isn’t vector a STL container?
- Best way to extract a subvector from a vector?
- When vectors are allocated, do they use memory on the heap or the stack?
- reduce the capacity of an stl vector
- How to sum up elements of a C++ vector?
- How to avoid memory leaks when using a vector of pointers to dynamically allocated objects in C++?
- Does vector::erase() on a vector of object pointers destroy the object itself?
- how do you insert the value in a sorted vector?
- How to use std::sort with a vector of structures and compare function?
- Reorder vector using a vector of indices [duplicate]
- std::vector, default construction, C++11 and breaking changes
- Initial capacity of vector in C++
- std::vector iterator invalidation
- array vs vector vs list
- How to make elements of vector unique? (remove non adjacent duplicates)
- How to downsize std::vector?
- C++ convert vector to vector
- What happens if you increment an iterator that is equal to the end iterator of an STL container
- Getting a vector into a function that expects a vector
- Can std::vector emplace_back copy construct from an element of the vector itself?
- std::vector capacity after copying
- iterator for 2d vector
- C++ template function compiles in header but not implementation
- vector and const
- How to get the address of the std::vector buffer start most elegantly?