在本教程中,我们将讨论一个程序,以了解C ++的下限。
C ++中的lower_bound()方法用于返回容器对象中的第一个数字,该数字不少于给定值。
#include <bits/stdc++.h>
int main(){
std::vector<int> v{ 10, 20, 30, 40, 50 };
std::cout << "向量包含:";
for (unsigned int i = 0; i < v.size(); i++)
std::cout << " " << v[i];
std::cout << "\n";
std::vector <int>::iterator low1, low2;
low1 = std::lower_bound(v.begin(), v.end(), 35);
low2 = std::lower_bound(v.begin(), v.end(), 55);
std::cout
<< "\nlower_bound for element 35 at position : "
<< (low1 - v.begin());
std::cout
<< "\nlower_bound for element 55 at position : "
<< (low2 - v.begin());
return 0;
}输出结果
向量包含: 10 20 30 40 50 lower_bound for element 35 at position : 3 lower_bound for element 55 at position : 5