Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying dereferenced STL iterators in gdb

I have an iterator to a map element, and I would like gdb to show me the values of the "first" and "second" elements of that iterator. For example:

std::map<int,double> aMap;
...fill map...
std::map<int,double>::const_iterator p = aMap.begin();

I can use p.first and p.second in the code, but can't see them in gdb. For what it's worth, in dbx one could do something like "print p.node.second_", but I can find anything similar in gbd.

I am totally willing to have a function into which I pass the object types, but I've been unable to get that to work either.

Any ideas? Thanks!

like image 234
kchoose2 Avatar asked Nov 26 '08 22:11

kchoose2


People also ask

Which STL function returns an iterator?

5. prev() :- This function returns the new iterator that the iterator would point after decrementing the positions mentioned in its arguments. 6.

How can I get data from iterator?

What you want is to access the contents of the container at the position designated by the iterator. You can access the contents at position it using *it . Similarly, you can call methods on the contents at position it (if the contents are an object) using it->method() .

Is iterator in STL?

Iterators are one of the four pillars of the Standard Template Library or STL in C++. An iterator is used to point to the memory address of the STL container classes.

How do STL iterators work?

An iterator is an object that can navigate over elements of STL containers. All iterator represents a certain position in a container. To make it work, iterators have the following basic operations which are exactly the interface of ordinary pointers when they are used to iterator over the elements of an array.


1 Answers

You can use p (*it)->second

like image 153
Raj Avatar answered Oct 03 '22 02:10

Raj