D
Diego Martins
I don't think your example will help you solve your problem.
Here's a capsule summary of what happens.
If the element you seek is in the container, then lower_bound returns an
iterator that refers to that element, and upper_bound returns an iterator
that refers to the next element (or one past the end if there is no such
element).
If the element is not in the container, then lower_bound and upper_bound
both return the same value, namely an iterator referring to the first
element *after* the one you seek (or one past the end if there is no such
element).
So if the map keys are strings, and you know the first few characters of the
string, you could use lower_bound to look for the given key.
If the result is one past the end of the container, you know that no element
begins with your key. Otherwise, the iterator gives you a place to start
looking.
For example, if your key is "foo", lower_bound will return the first element
that starts with "foo", if such an element exists. If not, it will return
either the first element that is > "foo" or one past the end if no such
element exists.
In your example, lower_bound(beg,end,"foo") will return an iterator
pointing to the first element starting with "foo". Can anyone give me
some advice how to use lower_bound() or upper_bound() to return an
iterator pointing to the next element after the ones started with "foo"
?
Diego Martins