//* Declaring a 2D vector of a specific size *

#include <iostream> #include <vector> using namespace std; template <typename T> void PRINT(const vector< vector<T> > &M) { for (unsigned int r=0; r<M.size(); r++) { // M.size() tells the number of rows for (unsigned int c=0; c<M[r].size(); c++) // M[r] is a 1D vector of columns cout << "\t" << M[r][c]; // and has its size information too cout << endl; } } int main() { unsigned int rows, cols; cout << "Please specify the size of the vector in rows and columns: "; cin >> rows >> cols; double ini; cout << "Please specify the initial value of each element: "; cin >> ini; vector<vector<double> > W(rows, vector<double>(cols, ini)); // create a 1D vector of vector<double> that has rows elements // initialize each element of 1D vector to a vector of doubles // of cols elements, and set each of those elements to ini PRINT(W); return(0); }