⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set_rang.cpp

📁 不错书对C++/C程序员很有用的大家不要错过.
💻 CPP
字号:
#ifdef __BCPLUSPLUS__
#include <set.h>
#else
#include <set>
#endif

#include <iostream.h>

using namespace std;
typedef set<int, less<int>> SET_INT;

void main(void)
 {
   SET_INT s1;
   SET_INT::iterator i;

   s1.insert(5);
   s1.insert(10);
   s1.insert(15);
   s1.insert(20);
   s1.insert(25);
   cout << "s1 -- starting at s1.lower_bound(12)" << endl;

// prints: 15,20,25
   for (i = s1.lower_bound(12); i != s1.end(); i++)
      cout << "s1 has " << *i << " in its set." << endl;
   cout << "s1 -- starting at s1.lower_bound(15)" << endl;

// prints: 15,20,25
   for (i = s1.lower_bound(15);i != s1.end(); i++)
      cout << "s1 has " << *i << " in its set." << endl;
   cout << "s1 -- starting at s1.upper_bound(12)" << endl;

// prints: 15,20,25
   for (i = s1.upper_bound(12); i != s1.end(); i++)
      cout << "s1 has " << *i << " in its set." << endl;
   cout << "s1 -- starting at s1.upper_bound(15)" << endl;

// prints: 20,25
   for (i = s1.upper_bound(15); i != s1.end(); i++)
     cout << "s1 has " << *i << " in its set." << endl;
   cout << "s1 -- s1.equal_range(12)" << endl;

// does not print anything
   for (i = s1.equal_range(12).first;i != s1.equal_range(12).second; i++)
      cout << "s1 has " << *i << " in its set." << endl;
   cout << "s1 -- s1.equal_range(15)" << endl;

// prints: 15
   for (i = s1.equal_range(15).first;i != s1.equal_range(15).second; i++)
      cout << "s1 has " << *i << " in its set." << endl;
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -