287

Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array.

2
  • 4
    support.microsoft.com/kb/198953 Commented 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! Commented Jul 15, 2014 at 1:13

5 Answers 5

687

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Incredible find. It does however only work with immediate values, no arithmetic or dynamic member access is allowed.
Note that you can also use a cast in the debug view. If pArray is of type void* you can type (char*) pArray, 10 which will display the content of the array interpreted as char.
Cannot do this in Visual Studio 2008 Express. If I add an expression "a+1,2" in the Watch Window, the foloowing error will occur: "error: + cannot be performed on 'pArray' and '1'". What version of VS are you using?
Anyone know if something similar is available in Eclipse?
I think you're probably using GDB as the debugger in Eclipse, in which case the equivalent syntax, *pArray@10 is what you're looking for. I haven't tried it in Eclipse, but it works in command-line GDB.
|
103

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

27

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

Looks great but doesnt support VS2013?? VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products. Supported Products : Microsoft.VisualStudio.Pro Version : [10.0] Version : [11.0] Version : [12.0] Version : [14.0]
It should do! I developed it in VS2013! What version of VS2013 (service pack / edition) are you running? If you search for ArrayPlotter in the Extension Manager (in the Online section) do you see it available within there?
Beautiful tool, works fine for me in VS2013.
20

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

-1

Hover your mouse cursor over the name of the array, then hover over the little (+) icon that appears.

1 Comment

For C++ this will only show you the first element

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.