Array Size

Jan 29, 2009 at 9:10am
Is there any way in which the size of array is assigned on the basis of user's choice?
I know only variables of type const can be used for declaring array of a particular size, but how do I do it when the size depends on value entered by user?
Jan 29, 2009 at 9:33am
I suggest you could use vectors instead.

http://www.cplusplus.com/reference/stl/vector/
Jan 29, 2009 at 10:25am
you cannot do it with array use vector instead
Jan 29, 2009 at 10:29am
You can also do it with new, but don't forget to use delete.

http://www.cplusplus.com/doc/tutorial/dynamic.html
Feb 1, 2009 at 8:54am
Thanks
Feb 1, 2009 at 4:49pm
You could also use malloc if you wanted, but elpis and mordekai posted much better solutions ;p.
Feb 3, 2009 at 7:38pm
malloc is a C style of memory allocation. better to recommend the use of new/delete instead.

Again, A vector is a better method.
Topic archived. No new replies allowed.