C++ set upper_bound()
#include <iostream> #include <set> #include <string> using namespace std; int main()/*from w w w.j av a2 s.c om*/ { // set of string objects set<string, less<string> > organic; // iterator to set set<string, less<string> >::iterator iter; organic.insert("C"); // insert organic compounds organic.insert("X"); organic.insert("C"); organic.insert("M"); organic.insert("C"); organic.insert("P"); organic.insert("A"); organic.insert("I"); organic.insert("C"); organic.insert("P"); organic.insert("C"); iter = organic.begin(); // display set while( iter != organic.end() ) cout << *iter++ << '\n'; string lower, upper; // display entries in range cout << "\nEnter range (example C Czz): "; cin >> lower >> upper; iter = organic.lower_bound(lower); while( iter != organic.upper_bound(upper) ) cout << *iter++ << '\n'; return 0; }