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
This is a discussion on Array Question within the C++ Programming forums, part of the General Programming Boards category; I want to get this out of the way. It may sound stupid, but I always end up doing it ...
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
-Save the whales. Collect the whole set.
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);
I used to be an adventurer like you... then I took an arrow to the knee.
That's nice, but what's the liscence info on that.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?
-Save the whales. Collect the whole set.
It's part of the STL.