7

I'm working in Vs2010 c++ with 2D arrays. I started off with a 1D pointer and used the operation [] as the following:

class CMatrix
{
    void clear();
public:
    int nRows;
    int nCols;
    short * MyMat;

    CMatrix();
    CMatrix(int r,int c);
    ~CMatrix(void);

    void SetMatrix(int r,int c);
    short * operator[] (const int row)
    {
        return MyMat + (row*nCols);
    }
};

I don't mind to change to 2D pointer.

However my problem is with debug. Because I'm using pointers I can't see the arrays content.

Are there any another options ?

I prefer not to use vector.

Ami DATA
  • 521
  • 2
  • 9
  • 14
  • Here is one take on a 2D array http://stackoverflow.com/a/13937325/942596. – andre Feb 13 '13 at 16:10
  • Here are more relevant links: http://stackoverflow.com/questions/972511/view-array-in-visual-studio-debugger and http://stackoverflow.com/questions/10536746/how-to-see-all-elements-of-a-two-dimensional-array-in-visual-studio-2010 – Ami DATA Feb 14 '13 at 08:06

2 Answers2

16

One way is to use use the Memory viewer. While debugging ( when stoped at a Breakpoint ), goto the menu Debug > Windows > Memory > Memory 1 to get the memory viewer. Then type-in the memory address ( copy paste the value from your pointer ) so that you can view the memory around that area of your program memory.

When you right click on memory viewer you can choose how you want to view the data ( as ANSI , as 4 integers, as 2 byte integers , as floats , bla bla... )

Also you can use the Watch window at the debug time. just use your pointer as an array ( e.g. if your pointer is char * t, the syntax t[0] will give your data pointed by the pointer t

Deamonpog
  • 805
  • 1
  • 10
  • 24
8

In the QuickWatch window, you can type the name of the pointer variable followed by a comma and the number of array indices you want to view, e.g. MyMat, 10.

Open Kastle
  • 427
  • 3
  • 13