Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array.
-
4support.microsoft.com/kb/198953a06e– a06e2012-08-22 19:35:51 +00:00Commented Aug 22, 2012 at 19:35
-
If it is a CArray, writing array.m_pData[pos] or array->m_pData[pos] (depending on the case) on the Watch Window lets you see the contents of array at the pos position!sergiol– sergiol2014-07-15 01:13:11 +00:00Commented Jul 15, 2014 at 1:13
5 Answers
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.
For example if pArray is the array, type pArray,10 in the watch window.
8 Comments
pArray is of type void* you can type (char*) pArray, 10 which will display the content of the array interpreted as char.*pArray@10 is what you're looking for. I haven't tried it in Eclipse, but it works in command-line GDB.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.
Comments
I use the ArrayDebugView add-in for 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#.
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.
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
3 Comments
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.
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.
Comments
Hover your mouse cursor over the name of the array, then hover over the little (+) icon that appears.