Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspecting STL containers in Visual Studio debugging

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

like image 383
kevin42 Avatar asked Sep 19 '08 19:09

kevin42


People also ask

Are STL containers passed by reference?

@BjörnPollex Yes! I forgot to mention that.

How are STL containers implemented in C++?

In C++, STL Unordered Associative Containers provide the unsorted versions of the associative container. Internally, unordered associative containers are implemented as hash table data structures.


2 Answers

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.

like image 99
Adam Rosenfield Avatar answered Oct 04 '22 01:10

Adam Rosenfield


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

like image 22
christopher_f Avatar answered Oct 04 '22 01:10

christopher_f