I need help with deleting elements from array

Dec 26, 2015 at 1:46pm
i have a struct array and it contains students first and last names
how do i go about deleting one student from my array.

I'm not entirely sure how to do this, can you give me an example on how to delete elements from struct arrays

i would appreciate the help!

Dec 26, 2015 at 2:31pm
Please note that this is a case where an array is a bad choice for the container. Arrays are bad when you have to add to or delete from the middle of the array.

If there are N elements in the array and you need to delete the k'th element then you copy the remaining elements down one position and decrement the number of valid items in the array:
1
2
3
4
for (int dst=k; dst < N-1; ++dst) {
    array[dst] = array[dst+1];
}
--N;

Topic archived. No new replies allowed.