I simply wanna erase the specified element in the range-based loop:
vector vec = { 3, 4, 5, 6, 7, 8 };
for (auto & i:vec)
{
if (i>5)
ve
It's quite simple: don't use a range-based loop. These loops are intended as a concise form for sequentially iterating over all the values in a container. If you want something more complicated (such as erasing or generally access to iterators), do it the explicit way:
for (auto it = begin(vec); it != end(vec);) {
if (*it > 5)
it = vec.erase(it);
else
++it;
}