Binary search for string in string array

Hey does anyone know how to search a given string in a string array using binary search?
1
2
3
4
5
6
7
8
9
string array[SIZE];

// ...
// [make sure array is sorted]

if ( std::binary_search(array, array + SIZE, "string to find") )
    cout << "Found" << endl;
else
    cout << "Not found" << endl;


However, you're probably better off using another data structure than the array.
BTW: This would not work with char*.
Last edited on
Topic archived. No new replies allowed.