C++ 在 Visual Studio 调试器中查看数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/972511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
View array in Visual Studio debugger?
提问by user20493
Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array.
是否可以在 Visual Studio 调试器中查看数组?QuickWatch 只显示数组的第一个元素。
回答by JaredPar
You can try this nice little trick for C++. Take the expression which gives you the array and then append a comma and the number of elements you want to see. Expanding that value will show you elements 0-(N-1) where N is the number you add after the comma.
您可以为 C++ 尝试这个不错的小技巧。获取为您提供数组的表达式,然后附加一个逗号和您想要查看的元素数。扩展该值将显示元素 0-(N-1),其中 N 是您在逗号后添加的数字。
For example if pArray
is the array, type pArray,10
in the watch window.
例如,如果pArray
是数组,则pArray,10
在监视窗口中键入。
回答by Ken
If you have a large array and only want to see a subsection of the array you can type this into the watch window;
如果你有一个很大的数组并且只想看到数组的一个子部分,你可以在监视窗口中输入它;
ptr+100,10
to show a list of the 10 elements starting at ptr[100]. Beware that the displayed array subscripts will start at [0], so you will have to remember that ptr[0] is really ptr[100] and ptr[1] is ptr[101] etc.
显示从 ptr[100] 开始的 10 个元素的列表。请注意,显示的数组下标将从 [0] 开始,因此您必须记住 ptr[0] 实际上是 ptr[100],ptr[1] 是 ptr[101] 等。
回答by Rodney Thomson
I use the ArrayDebugView add-in for Visual Studio (http://arraydebugview.sourceforge.net/).
我将 ArrayDebugView 插件用于 Visual Studio ( http://arraydebugview.sourceforge.net/)。
It seems to be a long dead project (but one I'm looking at continuing myself) but the add-in still works beautifully for me in VS2010 for both C++ and C#.
这似乎是一个死了很久的项目(但我正在考虑继续我自己的项目),但该插件在 VS2010 中对 C++ 和 C# 来说仍然很好用。
It has a few quirks (tab order, modal dialog, no close button) but the ability to plot the contents of an array in a graph more than make up for it.
它有一些怪癖(Tab 键顺序、模态对话框、没有关闭按钮),但能够在图形中绘制数组的内容,这足以弥补它。
Edit July 2014: I have finally built a new Visual Studio extension to replace ArrayebugView's functionality. It is available on the VIsual Studio Gallery, search for ArrayPlotter or go to http://visualstudiogallery.msdn.microsoft.com/2fde2c3c-5b83-4d2a-a71e-5fdd83ce6b96?SRC=Home
2014 年 7 月编辑:我终于构建了一个新的 Visual Studio 扩展来替换 ArrayebugView 的功能。它可在 VIsual Studio Gallery 上找到,搜索 ArrayPlotter 或访问http://visualstudiogallery.msdn.microsoft.com/2fde2c3c-5b83-4d2a-a71e-5fdd83ce6b96?SRC=Home
回答by stanigator
Are you trying to view an array with memory allocated dynamically? If not, you can view an array for C++ and C# by putting it in the watch window in the debugger, with its contents visible when you expand the array on the little (+) in the watch window by a left mouse-click.
您是否试图查看动态分配内存的数组?如果没有,您可以查看 C++ 和 C# 的数组,方法是将它放在调试器的监视窗口中,当您通过单击鼠标左键在监视窗口中的小 (+) 上展开数组时,可以看到其内容。
If it's a pointer to a dynamically allocated array, to view N contents of the pointer, type "pointer, N" in the watch window of the debugger. Note, N must be an integer or the debugger will give you an error saying it can't access the contents. Then, left click on the little (+) icon that appears to view the contents.
如果是指向动态分配数组的指针,要查看指针的N个内容,在调试器的观察窗口中输入“pointer, N”即可。注意,N 必须是一个整数,否则调试器会给你一个错误,说它不能访问内容。然后,左键单击出现的小 (+) 图标以查看内容。
回答by RichieHindle
Hover your mouse cursor over the name of the array, then hover over the little (+) icon that appears.
将鼠标光标悬停在阵列名称上,然后悬停在出现的小 (+) 图标上。