Jump to content
  • Advertisement
Sign in to follow this  
goldenpanda

How do I examine contents of stl vector when debugging?

This topic is 4839 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

When I try to look at an STL vector in the watch window in Visual Studio 2003, I can only look at the first element. For instance, NAME VALUE - m_tickRate {first=??? last=???} - std::_Vector_val<long,std::allocator<long> > {_Alval={...} } - _Alval {...} - std::_Allocator_base<long> {...} - _Myfirst 0x0104b350 - 7 - _Mylast 0x0104b368 - -33686019 - _Myend 0x0104b368 - -33686019 Trying to evaluate m_tickRate.at(0) gives me "CXX0039: Error: symbol is ambiguous". Evaluating m_tickRate[0] gives me "CXX0058: Error: overloaded operator not found". Is there a clever way to examine the contents of a vector, short of copying the contents to a normal C array? I tried various castings to resolve the ambiguity error, to no avail.

Share this post


Link to post
Share on other sites
Advertisement
There is an addon available at SourceForge which might help you out - I think it was actually written by one of the guys here on GDNet. It's not been updated in a little while, but should still do what you want. It's called VSEDebug.

Hope that helps.

-Mezz

Share this post


Link to post
Share on other sites
You cant just code a function to for loop through the vector and dump its contents to the console?

Share this post


Link to post
Share on other sites
You can copy it temporarily to an array if you want to examine it

int *t = &myVector[0];

since all the data in a vector is arranged as an array in memory.
EDIT: ok that's better than my solution :)

Share this post


Link to post
Share on other sites
Quote:
Original post by goldenpanda
Is there a clever way to examine the contents of a vector, short of copying the contents to a normal C array? I tried various castings to resolve the ambiguity error, to no avail.


Not exactly sure with VS2k3, but with Eclipse atop MinGW, I can do:

  #include <vector>
#include <iostream>

int main () {
std::vector< int > ints;
ints.push_back( 1 );
ints.push_back( 2 );
ints.push_back( 3 );
o //breakpoint here
std::cout << std::endl; //we dont want to reach the end of the function yet
}


______________
| Variables |_________________________________...
| - [#] ints
| - [#] _Vector_base<int,std::allocator<int> >
| - [#] public
| - [#] _M_impl
| + [#] allocator<int>
| - [#] public
| + [o>] _M_start = 0x003d2588
| + [o>] _M_finish = 0x003d2594
| + [o>] _M_end_of_storage = 0x003d2598
.
.
.


Then right click "_M_start", select "Display As Array...", enter in the starting index (0) and length (3 in this case - if you don't know this, do (_M_start - _M_finish) / sizeof( type ) ). Then:

______________
| Variables |_________________________________...
| - [/] ints
| - [/] _Vector_base<int,std::allocator<int> >
| - [/] public
| - [/] _M_impl
| + [/] allocator<int>
| - [/] public
| - [/] _M_start
| | |- [/ _M_start[0] = 1
| | |- [/ _M_start[1] = 2
| | \- [/ _M_start[2] = 3

| + [o>] _M_finish = 0x003d2594
| + [o>] _M_end_of_storage = 0x003d2598
.
.
.

Share this post


Link to post
Share on other sites
Quote:
Original post by goldenpanda
Wow thanks for typing that up. What did you do to get the courier font?


Bored programmer ASCII art ftw!! :D.

To see how a user posted something, click edit on their post (you can do this even if you wont be able to save the changes). In this case, I surrounded the text with [ code ] and [ /code ] (without the spaces, of course)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!