# Programmatically declare vectors

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 11-10-2008
franse
Programmatically declare vectors
I wonder if it is possible to programmatically declare vectors.

For example if I will return a number from somewhere wich could be 15.
Then I want programmatically declare 15 different vectors.

Code:

```int Number = 0; Number = 15; //Returned Number //Is it possible to programmatically here declare Num1 to Num15(15 vectors) //in any way ? std::vector<double> Num1;```
• 11-10-2008
tabstop
15 different vectors, or one vector with 15 elements? The vector constructor can take a size.
• 11-10-2008
Elysia
Why would you want to? Do you need an array of arrays (basically)?
Then it is possible to make a vector of vectors:
std::vector< std::vector<double> > myvec(Number);

But the vector itself is a dynamic array, not just a single variable.
• 11-10-2008
franse
Yes, I forgot to mention. I meen 15 different vector like this and then not elements:

Code:

```std::vector<double> Num1; std::vector<double> Num2; std::vector<double> Num3; ... ... until: std::vector<double> Num15;```
• 11-10-2008
tabstop
Then make a vector of vectors. Something like vector< vector<double> >.
• 11-10-2008
franse
Why I want to do that is because if my program will return in this case number 15. Then this number will stand for how many files there is in a folder ex.
Then I want to read in each file in each vector. 1 - 15.
Perheps this is not possible but there is an other approach to it.

Make a vector of vector, isn&#180;t that by creating dimensions of the vector ?
• 11-10-2008
Elysia
Mine and tabstop's suggestion will work for this. Make a vector of vectors.
• 11-10-2008
franse
I understand.. I just have to check if this solution will be good/ possible if I need to declare about 20 000 vectors.
Yes that is much :)
• 11-10-2008
tabstop
Quote:

Originally Posted by franse
Why I want to do that is because if my program will return in this case number 15. Then this number will stand for how many files there is in a folder ex.
Then I want to read in each file in each vector. 1 - 15.
Perheps this is not possible but there is an other approach to it.

Make a vector of vector, isnīt that by creating dimensions of the vector ?

Why would want a vector of vectors, then? Wouldn't you want a vector of file_data_structure (whatever you're using)? Even if you are using a vector for each file, you could typedef it so that people (and you!) know what's going on.
• 11-10-2008
franse
I haven&#180;t worked to much by doing vectors out of vector. Using typedef should look something like this, I think:
Code:

```typedef vector<std::string> string1; typedef vector<string1> string2; typedef vector<string2> string3;         String3 Three;```
By doing that, I have created 3 dimensions and if I will have like 5000 of these dimension, I am not sure if that will be difficult to know which dimension was for what or perheps it is.
• 11-10-2008
tabstop
If you have 5000 dimensions, you have way way way way way way way way way way bigger problems.
• 11-10-2008
franse
That is what I am a bit afraid of. What problem are you thinking of, is it memory problems, that it will take up much RAM ?
(I will fill each vector or dimension with say 50 lines &#225; 1 line = 50 characters from a file.)
• 11-10-2008
cpjust
5000 dimensions!!! :eek:
I'm pretty sure you don't know what that actually means.
I've never needed to use more than about 3 dimensions in my life.
• 11-10-2008
Elysia
I think that perhaps you do not need to read the entire file contents into memory. Waste of memory and cpu time.
Each vector can hold an entire file. So you will simply want ONE vector that can hold the vector who holds the file contents. Get me?
• 11-10-2008
tabstop
There's a limit on the number of dimensions, but I don't know what it is. If you have 5000 dimensions that means you have seriously done something wrong with your data structure.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last