Declaring number of array elements ?

Is it possible to allow user input of an int variable and then create or change an array size based on that variable?

So the user is asked how many Cows they want to customize,
they enter 5
so an array of 5 cows is created to customize
but later on after customizing 3 cows they decide they don't want another, can i allow them to change the initial int variable to 3 so that the array isn't populated with 5 cows?

Yes. std::vector (and other standard library containers) allocates dynamically the appropriate amount of memory and does provide a resize() function to change it later.

It is possible to do the allocations directly too.
Last edited on
Topic archived. No new replies allowed.