Use the approach with applying the standard algorithm std::remove_if.
As an example,
#include <vector>
#include <iterator>
#include <algorithm>
//...
std::vector<int> myvector{ 3, 3, 3, 3, 3, 3, 3, 1, 2, 3, 4, 5 , 2, 3, 4, 9 };
myvector.erase( std::remove_if( std::begin( myvector ), std::end( myvector ),
[]( const auto &item )
{
return 2 < item && item < 5;
} ), std::end( myvector ) );
for (const auto &item : myvector) std::cout << item << ' ';
std::cout << '\n';
The output of this code snippet is
1 2 5 2 9
Using this for loop
for(int i = 0; i < myvector.size(); i++)
is not right.
For example, if you have a vector with two items and the element with index 0 was eliminated in the first iteration, I will be incremented and equal to 1.
As long as I equals 1 and the value given by size() is greater than zero, the second element will not be erased.
Aside from that, such a technique with successive erasing of vector elements is inefficient.