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?
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- How to know full paths to DLL's from .csproj f
For,
add this to watch
Yes, simple. say you have
writing in the debugger:
would show you the content as if it were an array.
You can find a list of many things you can do with variables in the watch window in this gem in the docs: https://msdn.microsoft.com/en-us/library/75w45ekt.aspx
For a variable a, there are the things already mentioned in other answers like
but there's a whole lot of other specifiers for format and size, like:
a revisit:
let's assume you have a below pointer:
then you can write below in Visual Studio debug watch:
which will cast it into an array like below, and you can view all contents in one go.
Yet another way to do this is specified here in MSDN.
In short, you can display a character array as several types of string. If you've got an array declared as:
You could print it as a unicode string in the watch window with the following:
See the tables on the MSDN page for all of the different conversions possible since there are quite a few. Many different string variants, variants to print individual items in the array, etc.
In a watch window, add a comma after the name of the array, and the amount of items you want to be displayed.