
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
Upper Bound in C++
Here we will see that is the upper_bound() function in C++ STL. This function returns an iterator that points to the first element in the container, which is considered to go after val. The syntax is like:
iterator upper_bound (const value_type& val); const_iterator upper_bound (const value_type& val) const;
The return value is an iterator, pointing to the first element in the container which is considered to go after val.
Example
#include <iostream> #include <set> using namespace std; int main () { set<int> myset; set<int>::iterator itlow,itup; for (int i = 1; i < 10; i++) myset.insert(i*10); itup = myset.upper_bound (60); myset.erase(itup); cout << "myset contains:"; for (set<int>::iterator it = myset.begin(); it!=myset.end(); ++it) cout << ' ' << *it; }
Output
myset contains: 10 20 30 40 50 60 80 90
Advertisements