resize array

I'm a vb programmer moving towards Visual C++ and a doubt came up now, on a project.
Can i resize arrays in Visual C++?
How?
I've been searching and what i found was not what i was expecting. I found that in VC++, we need to create a new array with the desired size and move the content of the previous array into the new array.
Isn't there a better way?


My thanks in advanced

Comments

  • : I'm a vb programmer moving towards Visual C++ and a doubt came up
    : now, on a project.
    : Can i resize arrays in Visual C++?
    : How?
    : I've been searching and what i found was not what i was expecting. I
    : found that in VC++, we need to create a new array with the desired
    : size and move the content of the previous array into the new array.
    : Isn't there a better way?
    :
    :
    : My thanks in advanced

    the better way is using [link=http://www.cplusplus.com/reference/stl/vector/]vector[/link] - C++'s built in dynamic array.
    [hr][purple]~Donotalo()[/purple]
  • : I've been searching and what i found was not what i was expecting. I
    : found that in VC++, we need to create a new array with the desired
    : size and move the content of the previous array into the new array.
    : Isn't there a better way?


    Isn't this exactly what VB does behind the lines, though? I don't know how VB works, but if you do a "Redim" I bet it simply allocates a new array, hence the need of the "preserve" keyword to copy the old contents into the new one.
  • C++ vectors are usually the solution, but, if you have to use an array,
    the realloc() function is what you want to use. It allocates a new block
    of memory and copies the existing array for you. (or just extends the block of memory if you're lucky)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories