How do I examine contents of stl vector when debugging?

Started by
8 comments, last by Sharlin 18 years, 8 months ago
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.
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
You cant just code a function to for loop through the vector and dump its contents to the console?
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 :)
I've got the best answer: m_tickRate._Myfirst[3] :) (googled it)
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...
Wow thanks for typing that up. What did you do to get the courier font?
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 and (without the spaces, of course)
Very cool.

Why don't we put all these tags in an easy place to find?
Well, the FAQ is rather an easy place to find, now isn't it? :)

This topic is closed to new replies.

Advertisement