#include <vector>
#include <iostream>
int main()
{
typedef std::vector<int> Row;
std::vector<Row> my_vector;
for (int row = 0; row < 3; ++row)
{
Row my_row;
for (int col = 0; col < 3; ++col)
my_row.push_back( row*3 + col );
my_vector.push_back(my_row);
}
for (int row = 0; row < 3; ++row)
{
for (int col = 0; col < 3; ++col)
std::cout << my_vector[row][col] << ' ';
std::cout << std::endl;
}
}
0 1 2
3 4 5
6 7 8
I like to use the Typedef when doing this because it makes it very clear that we have a vector of rows. std::vector< std::vector<int> > is too verbose for me.