fill multidimensional vector through a loop?

Write your question here.
Hi!
I'm new with coding and somehow not good (yet) at finding solutions through the internet, so I hope you can help me.
I want to write 3 values in a vector, but I loop over these values n times, so I would like to keep track of them in the vector. Everytime a new value is calculated I would like to add it to my vector.
I thought about doing it with a for loop, but I don't know how.

To get a multidimensional vector, I take a vector of a vector, right?
Or should I use a map instead?

The code is just to clearify my idea, I know it doesn't work. I found out that push_back adds an element to the vector, but I would rather add them in a specific order, so that all v1 values are in the same column etc.

How can I loop through the vector to add the current values of v1, v2 and v3?

Thank you for taking time!

1
2
3
4
5
6
7
8
9
10
11
12
vector<double,vector<double, double> > numuList;
  for (int i=0; i<nevents; i++)
  {
    simtree->GetEntry(i); //get the data from a tree
    //calculate v1, v2, v3 with the data
    numuList.push_back(v1, v2, v3);
   } 




Looking at what you want I'd use a vector of a struct

1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct Data {
 double v1;
 double v2;
 double v3;
};

vector<Data> dataList;

for (int i = 0; i < X; ++i) {
 Data new_data;
 new_data.v1 = v1; // etc

 dataList.push_back(new_data);
}
thank you, this looks like what I want!
Topic archived. No new replies allowed.