Re: Another question about multidimensional vectors
Markus Pitha wrote:
How can I push_back() a vector which contains ints to a vector?
Just resize the vector and push back the int into the first vector.
For example:
values.resize(1); // now it has 1 int-vector inside it.
values[0].push_back(35); // Pushes 35 into the first vector.
If you want to *literally* push a vector of ints into 'values', you
can literally do that too. For example:
std::vector<int> aVector(1, 35); // initialized to have 1 value, 35
values.push_back(aVector);
I tried it in a different way like:
vector<int> xAxis;
vector<xAxis> yAxis;
I don't really understand what is it that you tried to accomplish
with that. If what you want is to create an x*y double-vector, you can
do it like this:
std::vector<std::vector<int> > values(xSize, std::vector<int>(ySize));
Now 'values' will be a vector with xSize vectors inside it, and each
one of these will have ySize ints inside them. Then you can simply
access the values like values[2][3].
Why do
I actually have to resize them although vectors are dynamic types?
You have to resize them *because* they are dynamic types, not *although*.