yeah, im looking for another method |
You could have asked there or at least shown what you already know and that you want something different.
It is not possible to change the size of an array.
The std::vector has two concepts:
size and
capacity.
The
capacity is the size of the array.
The
size is how many elements of the array are in use.
Therefore: size <= capacity
On
int array[] {2, 3, 42, 4, 5};
size == capacity == 5.
After the "delete" the size must be 2 (but capacity remains 5) and the odd values must be at the first 'size' elements of the array.
The
std::remove_if(std::begin(array), std::end(array), [](const auto el) {return el % 2 == 0; })
moves the odd values within the array and
returns an iterator to one past last odd element.
It is possible to calculate the new 'size' from the returned iterator. See
std::distance
The output after the "delete" must show only the 'size' first elements of the array, not the whole array.