Hello everyone,
I need to make a constructor that initialize a 2d vector array by zeros or nulls......
how can i do that ._.
tried nested loops like in 2d arrays but failed
should i use push_back?or is there a way i can do this without it?

05-30-2011

phantomotap

What have you tried?

Soma

05-30-2011

ManyTimes

Hello, as phantomotap says: tried anything? Show the code.

std::vector can be initialized just when you are creating it, like this:

Code:

//Creates 2D vector of size 10 and the 0 in the line below defines the default size.
std::vector<std::vector <int>> Storage(10, std::vector<int>(10, 0));

If you define a vector like this (with no default value):
std::vector<std::vector <int>> Storage(10, std::vector<int>(10));
Then initialize it through a loop with another inner loop: