Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Lower bound in C++
In this tutorial, we will be discussing a program to understand the lower bound in C++.
lower_bound() method in C++ is used to return the very first number in the container object which is not less than the given value.
Example
#include <bits/stdc++.h>
int main(){
std::vector<int> v{ 10, 20, 30, 40, 50 };
std::cout << "Vector contains :";
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;
}
Output
Vector contains : 10 20 30 40 50 lower_bound for element 35 at position : 3 lower_bound for element 55 at position : 5
Advertisements