# Infinite Arrays?

• 06-06-2005
tommy
Infinite Arrays?
How can I make an infinite-size array? I saw something about vector<type> but I'm a bit confused on how to use them... help?
• 06-06-2005
Prelude
You can't make an infinite array unless you have infinite memory. But you can use a container that grows as needed:
Code:

```#include <iostream> #include <vector> int main() {   std::vector<int> v; // Define a vector of int called v   // Append 10 values to the vector   for (int i = 0; i < 10; i++)     v.push_back(i);   // Print out all elements of the vector   for (int i = 0; i < v.size(); i++)     std::cout<< v.at(i) <<'\n'; }```
• 06-06-2005
tommy
Thanks!

Question: Is there any way to use those with structs? Like vector<struct> or something?
• 06-06-2005
Thantos
you can have any type in a vector, including another vector ;)
• 06-06-2005
tommy
Well, by this, I mean like having multiple structs. You know, like:

Code:

```struct blah_struct[] { int blah_var; } blah[10]```
How would I have a vector replace the blah[10]?
• 06-06-2005
Daved
In your example the type of your structure is blah_struct. Just replace int with the name of your type:
Code:

```#include <iostream> #include <vector>   struct blah_struct { int blah_var; };   int main() {   // Define a vector of blah_struct called v starting with 10 objects.   std::vector<blah_struct> blah_vector(10);     // Print out all elements of the vector   for (int i = 0; i < blah_vector.size(); i++)         std::cout<< blah_vector.at(i).blah_var <<'\n'; }```
If your struct is not a simple one with only POD objects, you'll have to be careful about using it in a container. It might need a copy constructor and copy assignment operator.