Archived

This topic is now archived and is closed to further replies.

Debugging with STL

This topic is 5653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone have any easy ways to see what''s in STL containers in a debugger. I use std::vector for dynamic arrays a great deal and it''s a pain to not be able to type MyArray[5] into the debugger and have it show its value like I can with regular arrays. I''m using VC++.net Jack

Share this post


Link to post
Share on other sites
one trick i have used to deal with that is assign to a local reference.


  

MyClass

vector MyClass;

MyClass& localRef = MyClass[2];



Of course, you have to range check the vector, but at least you can easily see the class type''s details

Share this post


Link to post
Share on other sites
Here''s what you can do. A vector should store the pointer to its first element. Expand the vector contents in Variables window and drag the first element pointer over to the watch window. Then you can add ''+1'', ''+5'' etc. to the expression to watch the respective elements. This works for me in MSVC6.

Share this post


Link to post
Share on other sites
It''s pretty horrible to get STL working correctly in the debugger. Often you need to know the container internal structure.

ie. cont._First to see the container data.

Search the public.microsoft.vc newsgroup on debugging STL. Answers are there

Share this post


Link to post
Share on other sites
You might want to give the "ToDo Cached" add-in a try. Go here and download it. One of the things id does is add a new watch window that knows how to evaluate the common STL containers (including nested ones).

HTH

Share this post


Link to post
Share on other sites