[Solved] Lower_bound matching wrong strings


Try using this function that’s a variation of the standard binary_search(). It returns an iterator to the matching element (the ‘lowest’ one) if the value is found in the range, and an iterator equal to last (usually end()) when there’s no match:

template< class ForwardIt, class T >
ForwardIt binary_search_ex(ForwardIt first, ForwardIt last, const T& value)
{
    ForwardIt it = std::lower_bound(first, last, value);

    if ((it != last) && (value < *it)) it = last;

    return it;
}

solved Lower_bound matching wrong strings