Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
STL binary search
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Ivan Vecerina, post: 1513463"] Actually, std::binary_search returns a bool telling whether the item was found or not. Yes, you can use std::lower_bound in <algorithm>. This one returns an iterator, which can readily be converted to an index: index = lower_bound( list.begin(), list.end(), valToBeFound ) - list.begin(); Note that if you are not sure that the string to be found is in the list, you need to (1) verify that the resut of lower_bound is not list.end() and (2) verify that the result is actually equal to the searched string. Cheers, Ivan [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
STL binary search
Top