// MatrixFromVector.cpp

// This program demonstrates how to create a dynamically sized
// matrix by using the STL's vector class.

#include <vector>
#include <iostream>
using namespace std;

typedef vector< vector<char> > matrix_type;

// function prototypes (function declarations)
void print(const matrix_type&);

// main simply creates a 2D matrix
int main()
{
	int size = 7;						// it works with a non-const int
//	int array[size];					// this line errors because of non-const int
	matrix_type  matrix;				// creates a zero-sized matrix

	matrix.resize(size);				// resize matrix'es # of rows
	for (int a = 0; a < size; ++a)
	{
		matrix[a].resize(size); 		// resizes matrix row's # of cols

		for (int b = 0; b < size; ++b)	// insert stuff into the matrix
		{
			matrix[a][b] = '*';			// notice the use of [][]
		}
	}

	print(matrix);

	return 0;
}

// print simply outputs a 2D matrix to the console
void print(const matrix_type& mat)
{
	for (int i = 0; i < mat.size(); ++i)
	{
		for (int j = 0; j < mat[i].size(); ++j)
			cout << mat[i][j] << ' ';
		cout << endl;
	}
}