Convert iterator to pointer?

here it is, obtaining a reference to the coresponding pointer of an iterator use : example: string my_str= “hello world”; string::iterator it(my_str.begin()); char* pointer_inside_buffer=&(*it); //<– [notice operator * returns a reference so doing & on a reference will give you the address].

Using C++ vector::insert() to add to end of vector

a.push_back(x) is defined to have identical semantics to (void)a.insert(a.end(),x) for sequence containers that support it. See table 68 in ISO/IEC 14882:2003 23.1.1/12 [lib.sequence.reqmts]. Regarding the running time of vector.push_back(x) vs. vector.insert(vector.end(), x) consider the emphasized part: Table 68 lists sequence operations that are provided for some types of sequential containers but not others. An implementation … Read more

Last key in a std::map

Yes. Map is a sorted container, the reverse iterator must return the elements in reverse (i.e. decreasing) order of their keys. [Edit: as Charles Bailey points out in his answer, your code gives the greatest key if it exists – i.e. if the map is non-empty]

Removing item from vector while iterating?

The most readable way I’ve done this in the past is to use std::vector::erase combined with std::remove_if. In the example below, I use this combination to remove any number less than 10 from a vector. (For non-c++0x, you can just replace the lambda below with your own predicate:) // a list of ints int myInts[] … Read more