所使用的库函数:
#include <algorithm>
所表示的含义:
lower_bound(起始地址,结束地址,要查找的数值) 返回的是数值 第一个 出现的位置。
upper_bound(起始地址,结束地址,要查找的数值) 返回的是 第一个大于待查找数值 出现的位置。
https://www.cnblogs.com/Tang-tangt/p/9291018.html
示例代码:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> ve(8, 0);
for (int i = 0; i < 8; i++)
{
ve[i] = i;
}
auto low = lower_bound(ve.begin(), ve.end(), 3)-ve.begin();
int upp = upper_bound(ve.begin(), ve.end(), 3) - ve.begin();
cout<<low<<endl;
cout << upp << endl;
}
输出结果: