View Single Post
Old 09-11-2005, 07:49 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Nothing beats some code. and besides, you should check out:
C++ Multi Dimensional Array using Vectors.
Code:
#include <iostream>
#include <vector>
#include <cstdlib>

using std::size_t;
using std::vector;
int main()
{  
  vector<vector<int> > Matrix;
  
  //Create the 2x2 matrix.
  size_t rows = 2;
  size_t cols = 2;  
  // 1: set the number of rows.
  Matrix.resize(rows);
  // 2: set the number of columns per row.
  for(size_t i = 0; i < rows; ++i)
  {
    Matrix[i].resize(cols);
  }
  
  Matrix[0][0] = 1;
  Matrix[0][1] = 2;
  Matrix[1][0] = 3;
  Matrix[1][1] = 4;
  
  //Demo of row/column workings.
  for(size_t i = 0; i < rows; ++i)
  {
    for(size_t j = 0; j < cols; ++j)
    {
      std::cout <<"["<<i<<"]"<<"["<<j<<"] = " <<Matrix[i][j]<<std::endl;
    }
  }  
  
  return 0;
}
__________________
Valmont is offline   Reply With Quote