title: Heap Corruption Detected in C++
body: <p>I keep getting the error Heap Corruption Detected. I have read through several questions on here, but I can't quite find out what is causing this in my code. I am trying to create a 2d array that will hold a matrix that is read from a text file. </p>
  
  <pre><code>// Create a 2d matrix to hold the matrix (i = rows, j = columns)
  matrix = new int*[cols];
  
  for(int i = 0; i &lt;= cols; i++) {
      matrix[i] = new int[rows];
  }
  
  // Populate the matrix from the text file
  for (int i = 0; i &lt; rows; i++) {
      for (int j = 0; j &lt; cols; j++) {
          inputFile &gt;&gt; matrix[i][j];
      }
  }
  </code></pre>
  
  <p>My destructor is:</p>
  
  <pre><code>for(int i = 0; i &lt;= cols; i++) {
      delete[] matrix[i];
  }
  
  delete[] matrix;
  </code></pre>
  
  <p>I've tried debugging, but that does do much help in this case. Any suggestions?</p>