Resizing an array?

1
2
int array[100]; //If I do this
array[101]=1; //Then this is invalid 

but what if I want to do it?
How to resize the array to be larger?

EDIT: wait a minute, compiler doesn't send me any error message.
in fact it works. idk o_O

Well anyway, never mind
Last edited on
You can't resize arrays. What you can do is having a dynamically allocated array int* array = new int[100]; To resize the array you allocate a larger array and copy the elements to the new array and delete the old array. This is very boring and error prone so that's why there is a class that can do these things easier for you, called std::vector.
http://www.cplusplus.com/reference/stl/vector/
Topic archived. No new replies allowed.