# How do I examine contents of stl vector when debugging?

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

## 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 on other sites
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 on other sites
You cant just code a function to for loop through the vector and dump its contents to the console?

##### 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 on other sites
Quote:
 Original post by goldenpandaIs 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 on other sites
Wow thanks for typing that up. What did you do to get the courier font?

##### Share on other sites
Quote:
 Original post by goldenpandaWow 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 on other sites
Very cool.

Why don't we put all these tags in an easy place to find?

##### Share on other sites
Well, the FAQ is rather an easy place to find, now isn't it? :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• ### Forum Statistics

• Total Topics
634070
• Total Posts
3015330
×