Table of variable size

Hello,
I would like to create a table but I dont know how big. Thats why I want to use variable to describe its size. Something like that:
1
2
int x = 5; //I will use a function to set x
int Table[x];

What should I do to make it work?
Use vector:
1
2
int x = 5;
std::vector<int> table(x);

Or use dynamic memory allocation:
1
2
3
4
5
int x = 5;
int* table = new int[x];
//Do not forget to delete array whn you are done!
//Or face memory leak
delete[] table;
and if I decide to use dynamic memory allocation can I do things like that:
1
2
3
4
for(int y = 0; y < x; y++)
{
   Table[y] = SomeFunction();
}

or it works in some other way?
You can do this with both vector and dynamic allocation. The both works the same way. But vector handles memory automaticly and have many useful member functions.
Thanks for you help ;)
Topic archived. No new replies allowed.