#include <iostream> #include <string> #include <vector> #include <ctype.h> using namespace std; int main() { vector<int> v1; vector<int>::iterator start; vector<int>::iterator end; vector<int>::iterator mid; int loop = 0; int key = 11; for (loop = 0; loop < 10; ++loop) { v1.push_back(loop); } start = v1.begin(); end = v1.end(); while(start < end) { mid = start + (end - start)/2; if(*mid == key) { cout<< mid - v1.begin(); return 0; } else if(*mid > key) { end = mid; } else { start = mid + 1; } } cout << "can not find the matched value"<<endl; return -1; }