How to dynamically resize an array when it runs out of space?

Does anybody have an idea on how to do this. I think you have to create a new array bigger than the original one , and copy all the information stored in the old array to the new re-sized array. I might have answered my own question , but does anybody know how to implement this with code.
Thank you.
Last edited on
Last edited on
Forgot to mention , No vectors
Well yeah then, you answered yourself.

You create a bigger array, copy your data back and delete the old array.

Type * newdata = new Type[newsize];
for(unsigned int i = 0; i < oldsize; ++i)
    newdata[i] = olddata[i];
delete[] olddata;
olddata = newdata;
Last edited on
Topic archived. No new replies allowed.