+ 12
Hi people, how can i flush or delete the cells of an array of ints in c++?
5 Réponses
+ 11
OK but i' m sorry I said that badly. i was wondering how to delete the memory in the cells , not necessarily the cells themselves
+ 10
mmm.. OK thenks i will try all
+ 5
Umbe, can you give some more details on the code?
how was the array allocated?
int arr[SIZE];
or
int *arr = new int[SIZE];
+ 5
You can't delete array cells
int arr[] = {1,2,3,4} for example has a fixed size of 4, you can't make it smaller or bigger.
In order to support deletion ( and adding ) you have to look for dynamic arrays ( int * arr = new int[size])
But since this is quite hard to manage correctly C++ provides you with wrappers to manage this for you
vectors are what you're looking for which support adding and deletion.
http://www.cplusplus.com/reference/vector/vector/
+ 5
If you have the array allocated by new you can simply call
delete[] arr;