I want to get this out of the way. It may sound stupid, but I always end up doing it wrong and causing all sorts of problems.
How do I make an array with an unlimited amount of elements.
Thanks
Printable View
I want to get this out of the way. It may sound stupid, but I always end up doing it wrong and causing all sorts of problems.
How do I make an array with an unlimited amount of elements.
Thanks
You can't. To create a static or even dynamic array you have to specify the size.
If you want to have a container that can hold an "unlimited" (which of course is not possible because you can always run out of memory :) ) number of elements, you can use a linked list or other such data structure.
Use one of the provided STL containers, probably a vector would be best for you. For example...
Code:#include <vector>
...
vector<int> v1; // Create a vector to hold ints
...
// Now just keep pushing ints onto the vector to your heart's content.
// It will keep growing and growing...
v1.push_back(1);
v1.push_back(14);
...
v1.push_back(-6);
That's nice, but what's the liscence info on that.Quote:
Originally posted by hk_mp5kpdw
Use one of the provided STL containers, probably a vector would be best for you. For example...
Code:#include <vector>
...
vector<int> v1; // Create a vector to hold ints
...
// Now just keep pushing ints onto the vector to your heart's content.
// It will keep growing and growing...
v1.push_back(1);
v1.push_back(14);
...
v1.push_back(-6);
Do big game developers use it?
It's part of the STL.