#include <vector> #include <iostream> using namespace std; int main() { vector<int> text{1,2,3,4,5,6,7,8,9,10}; int sought; cin>>sought; //迭代器二分搜索,text必须有序 auto beg=text.begin(),end=text.end(); auto mid=beg+(end-beg)/2; while(mid!=end&&*mid!=sought){ if(sought<*mid) end=mid; else beg=mid+1; mid=beg+(end-beg)/2; } if(mid==end) cout<<"not found. "; else cout<<*mid<<" is found. "; return 0; }