User forums > Using Code::Blocks

see content of a vector in debugging

(1/26) > >>

taram:
hi,

I use c::b (svn 5616)  and in my c::b project I have defined a typdef like this:

typedef vector<string> vstr;

And use it like following:

--------------------------
vstr v;

v.push_back("bla bla");
---------------------------

Everything works fine.

But when I debug, I can not see in the  "Local variabel"  an "understandable" content of the string vector.

When I open the "local watches" I only see "_M_start"  and "_M_finish" etc. with a hex number.




The only thing which is working when I watch a concrete cell of the vector is:


Add watch -->v[0]


then I can see the string of the first element of the string vector.

Is there a way to see all strings of the string vector in the debugger? That would be great.

The "v[0]" (element view) works fine but it would be very convenient to see all strings in the string vector "en block".


Thanks for your help

Martin




ollydbg:
I test your code, found it is even bad in my system(MinGW, WindowsXP), I can't view "v[0]".
See my screenshot


[attachment deleted by admin]

Jenna:
If v[0] works for you, you can try to watch v as array (add it to watch window, edit it and check watch as array).

Jenna:

--- Quote from: ollydbg on June 07, 2009, 08:45:44 am ---I test your code, found it is even bad in my system(MinGW, WindowsXP), I can't view "v[0]".
See my screenshot


--- End quote ---
You have to use the []-operator in your program, otherwise it gets not compiled in and therefore cannot be used by gdb.

@taram:
watching the variable as array does not work here.

ollydbg:
Thanks Jens for your hints.

Here is a workaround.

--- Code: ---#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> vstr;

int main()
{
    vstr v;
    v.push_back("bla bla");
    string v0 = v[0];
    cout << "Hello world!" << endl;
    return 0;
}

I can only watch "v0" (see the screen shot)



--- End code ---

[attachment deleted by admin]

Navigation

[0] Message Index

[#] Next page

Go to full version