how to increase the size of an array
I have an array that i need to increase the size of depending on the object being used.
How would I increase the size of this array if I needed to?
1 2 3 4
|
// this is the array that's created each time my function is called
char * temp = new char[max]; //max is an int
|
The easiest method is to use std::vector<char> (or std::string) rather than plain array.
But can it be a char array
Last edited on
you can create an array for the object and set the array's size when creating it.
but you can not change it's size during runtime.
I would just use a vector for that task.
"need"?
1 2 3 4 5 6 7
|
char * temp = new char[max];
char * foo = new char[max+more] {};
std::copy( temp, temp+max, foo );
delete [] temp;
temp = foo;
foo = nullptr;
|
Topic archived. No new replies allowed.