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!
5. prev() :- This function returns the new iterator that the iterator would point after decrementing the positions mentioned in its arguments. 6.
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() .
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.
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.
You can use p (*it)->second
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With