views:

2457

answers:

6

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)?

+2  A: 

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

christopher_f
+3  A: 

Visual Studio 2008, at least for me, displays the contents of STL containers in the standard mouseover contents box.

psoul
Me too and I'm sure VS2005 did the same.
Rob
+2  A: 

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

maxbog
A: 

You can also right-click any value in your watch, and choose 'add watch'. This can be useful if you only need to look at one element of a map or set.

It also leads to the solution that christopher_f posted for vectors - ((v)._Myfirst)[index]

tfinniga
+3  A: 

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.

Adam Rosenfield
+5  A: 

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.

Steve Steiner