iterator lower_bound( const key_type &key );
iterator upper_bound( const key_type &key );
iterator lower_bound( const key_type &key ): 返回一个
迭代器,指向
键值>= key的第一个元素。
iterator upper_bound( const key_type &key ): 返回一个迭代器,指向
键值> key的第一个元素。
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef vector<int> vec;
int main()
{
int kg[20]={2,4,5,8,1,3,9,7,6};
sort(kg,kg+9);
vec aa(kg,kg+9);
int cnt=lower_bound(kg,kg+9,7)-kg;//lower_bound对数组进行操作
int cnt2=lower_bound(aa.begin(),aa.end(),100)-aa.begin(); //对向量进行操作
cout<<cnt<<" "<<cnt2<<endl;
aa.insert(aa.begin()+cnt2,8888888);
for(int i=0;i+aa.begin()!=aa.end();i++)//对迭代器的灵活运用
cout<<aa[i]<<" ";
system("pause");
return 0;}