Deleting array elements

I am new to programming. I justlearned how to implement arrays both from user input and getting it from a file. I would like to know if anyone could help me in deleting an element from an array in C++? If so I'd greatly appreciate it.
Last edited on
Here is the code I suggest. it will delete your array element. Suppose you found an array element in the position at position i in the array then the code goes like this

for ( j=i;j<MaxSize;j++ ) Array[j] = Array[j+1];


This code replace the element you want to delete.
That will actually access out of bounds on Array (when j = MaxSize-1). Simply, you can't 'delete' elements from an array, because arrays are fixed-size.
you can't 'delete' elements from an array, that's true but u can replace the content with its succesive elements. virtually 'delete' an array element.
You are write the code I suggest make an assignment out of the scope if we use j<MaxSize; so we need to use j<MaxSize-1;
@shysan
U mean that if I define a array like this

#define MaxSize 6
int main()
{
        int a[ MaxSize ];

        return 0;
}

I only have the space from a[ 0 ] to a[ 5 ]. And a[ 6 ] is unavailable.
To "delete" an element from an array you should define a "deleted value" which will differ from all other acceptable values. Otherwise it is difficult to determine whether an element of an array is deleted or not.
Last edited on
Thank you all. The feedback I received was very helpful. Glad I joined this forum. Hope to be on the giving end of information very soon!
Topic archived. No new replies allowed.