通过调试查看指针内容

通过调试查看指针内容

本文介绍了vs2010 c++ 通过调试查看指针内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有二维数组的 Vs2010 c++ 工作.我从一维指针开始,并使用操作 [] 如下:

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);
    }
};

我不介意改为 2D 指针.

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.

还有其他选择吗?

我不喜欢使用矢量.

推荐答案

一种方法是使用 Memory 查看器.调试时(在断点处停止时),转到菜单 Debug > Windows > Memory > Memory 1获取内存查看器.然后输入内存地址(复制粘贴指针中的值),以便您可以查看程序内存区域周围的内存.

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.

当您右键单击内存查看器时,您可以选择查看数据的方式(作为 ANSI 、作为 4 个整数、作为 2 字节整数、作为浮点数、bla bla...)

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... )

您也可以在调试时使用 Watch 窗口.只需将您的指针用作数组(例如,如果您的指针是 char * t,语法 t[0] 将给出由指针 t

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

这篇关于vs2010 c++ 通过调试查看指针内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:50