如何在 Visual Studio 调试器中显示动态分配的数组?

2021-12-07 00:00:00 visual-studio debugging c c++

如果您有一个静态分配的数组,Visual Studio 调试器可以轻松显示所有数组元素.但是,如果您有一个动态分配并由指针指向的数组,则当您单击 + 将其展开时,它只会显示该数组的第一个元素.有没有一种简单的方法可以告诉调试器,将此数据显示为类型为 Foo 且大小为 X 的数组?

If you have a statically allocated array, the Visual Studio debugger can easily display all of the array elements. However, if you have an array allocated dynamically and pointed to by a pointer, it will only display the first element of the array when you click the + to expand it. Is there an easy way to tell the debugger, show me this data as an array of type Foo and size X?

推荐答案

是的,很简单.说你有

char *a = new char[10];

在调试器中写入:

a,10

会像数组一样显示内容.

would show you the content as if it were an array.

相关文章