Inspecting STL containers in Visual Studio debugging

34,176

Solution 1

For vectors, this thread on the msdn forums has a code snippet for setting a watch on a vector index that might help.

Solution 2

If you want to watch more than one element at the same time, you can append a comma and the number of elements as so:

(v._Myfirst)[startIndex], count

However, note that count must be a constant, it cannot be the result of another expression.

Solution 3

In VS2005 and VS 2008 you can see the contents of STL containers. The rules for getting at the data are in autoexp.dat "c:\Program Files\Microsoft Visual Studio 9\Common7\Packages\Debugger\autoexp.dat".

AutoExp.dat is meant to be customized. However, the STL defs are under a section called [Visualizer]. If you can figure out the language used in that section, more power to you, however I'd recommend just leaving that part alone.

Autoexp.dat existed in VS2003, but there was no support for STL containers ([Visualizer] didn't exist). In VS2003 you have to manually navigate the underlying data representation.

By modifying autoexp.dat it is possible to add rules for navigating the data representation of your own types so they are easier to debug. If you do this, you should only add to the stuff under [AutoExp]. Be careful and keep a back up of this file before you modify it.

Solution 4

To view the nth element of a container in the Visual Studio debugger, use:

container.operator[](n)

Solution 5

You could create a custom visualiser Check this out: http://www.virtualdub.org/blog/pivot/entry.php?id=120

Share:
34,176
kevin42
Author by

kevin42

I'm just a boring guy that spends too much time designing and developing software.

Updated on February 01, 2022

Comments

  • kevin42
    kevin42 over 2 years

    If I have a std::vector or std::map variable, and I want to see the contents, it's a big pain to see the nth element while debugging. Is there a plugin, or some trick to making it easier to watch STL container variables while debugging (VS2003/2005/2008)?