c++ binary search on string

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<string>vec;
int main()
{
	vec.push_back("10");
	vec.push_back("20");
	vec.push_back("30");
	vec.push_back("40");
	vec.push_back("50");
	vec.push_back("60");
}


how can i use binary_search() to find an index of a string from "vec" ?? i also need the lower_bound() and upper_bound() index .

thanks in advance :-)
binary_search only returns a boolean, so you won't get a position from it. lower_bound and upper_bound return iterators. Since these are random access iterators, you cans subtract vec.begin from them to get the index.
Topic archived. No new replies allowed.