views:

201

answers:

4

Hello,

I'm trying to debug some C++ code but I can't see the values in a multi-dimensional array while debugging

I have a dynamically allocated pointer (double **A).

When I try to watch the value of this array I just get the first value, I can't see the remaining values.

Any ideas?

TIA

A: 

Iterate through and print out each value. Roughly something like this:

void print2DArray(double **A, int width, int height) {
    for (int i=0; i<width; i++) {
        for (int j=0; j<height; j++) {
            cout<<A[i][j]<<" ";
        }
        cout<<endl;
    }
}
MatrixFrog
A: 

Through the debugger you may write explicitly in the watch window A[2][1] etc..

Edited - after the code presented:

int main() {
    double **A; 
    double M = 4;
    A = new double *[M]; //define M by M matrix
    for( int k =0; k < M; k++) { 
        A[k] = new double [M]; 
    } 
    //assign values to matrix 
    for (int i = 0; i < M; i++) { 
        for (int j = 0; j < M; j++) { 
            if ( j == i) { 
                A[i][j] = 2; 
            } else { 
                A[i][j] = 1; 
            }
        }
    }
    return 0;
}

I put break point on the return 0 and add some test values to the watch window:

    A[0][0] 2.0000000000000000 double
    A[0][1] 1.0000000000000000 double
    A[0][2] 1.0000000000000000 double
    A[1][0] 1.0000000000000000 double
    A[1][1] 2.0000000000000000 double
    A[1][2] 1.0000000000000000 double

It seems fine. What do you get when you're doing the same? Where is the problem? You can also print the values to screen as MatrixFrog suggested.

Y. Shoham
That doesn't work. I get the values of the first row onlyso A[0][0] = A[1][0]=A[2][0] and so on. The array is:2 1 11 2 11 1 2So this is clearly wrong. I'm starting to question my decision not use C# for this.
yomismo
That's very odd. I think you should post the whole code of creating and populating the array.
Y. Shoham
there you go:double **A; double m; A = new double *[M]; //define M by M matrix for( int k =0; k < M; k++) { A[k] = new double [M]; } //assign values to matrix for (int i = 0; i < M; i++) { for (int j = 0; j < M; j++) { if ( j == i) { A[i][j] = 2; } else { A[i][j] = 1; } }
yomismo
My problem is that I don't get what I should, instead I get A[0][0]=A[1][0] =2 ; A[0][1]=A[1][1] = 1 and so on. In fact, I just stepped through watching all values of A, while assigning the values w and A[1][0] gets assigned at the same time as A[0][0]. This is driving me insane. Help!!!! :)
yomismo
Try to run **exactly** the code I posted. It's complete program; run this in new empty project. Does it work fine?
Y. Shoham
A: 

The simplest way to see large data arrays in VS is to use a memory window instead of a Watch window or the Autos or Locals window. Just drag your pointer value to the memory window's address box.

Die in Sente
A: 

This is what I get: http://www.flickr.com/photos/42475383@N03/4247049191/

edit.

I was using a CLR console project. I tried a win32 console and it works fine. I can see a google moment coming up to find out what a CLR project is.

Yomismo