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?

thanks.

Recommended Answers

All 3 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.