I have some code that generates numbers, and I wish to add them to some kind of list, I did research and an array seems to be close to what I want, but I can't find how to add a generated variable to it.

Or is there some other kind of list, or something that would allow me to add variables at any time and print off the whole list at the end?


10 Years
Discussion Span
Last Post by Matt Tacular

Arrays seem to be what you want. Static arrays are declared before hand, and you can store data in them.

int intArray[20]; // stores up to 20 integers
cin >> myArray[5]; // user enters a number into the 6th element

Of course, statically allocated arrays have their problems, so dynamic memory may have been what you wanted. In that case, you can either use linked lists as shown by Dave, or you can use vectors or dynamic arrays.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.