chapter9-27.cpp

来自「STL程序员开发指南源码」· C++ 代码 · 共 27 行

CPP
27
字号
//文件名:CHAPTER9-27.cpp
#include <set>
#include <iostream>
#if _MSC_VER > 1020   // if VC++ version is > 4.2
   using namespace std;  // std c++ libs implemented in std
#endif
int main( )
{
   typedef set<int, less< int > > IntSet;
   IntSet s1;
   set <int, less< int > > :: const_iterator s1_RcIter;
   s1.insert( 10 );
   s1.insert( 20 );
   s1.insert( 30 );
   pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
   p1 = s1.equal_range( 20 );
   cout << "The upper bound of the element with "
        << "a key of 20 in the set s1 is: "<< *(p1.second) << "." << endl;
   cout << "The lower bound of the element with "
        << "a key of 20 in the set s1 is: "<< *(p1.first) << "." << endl;
   // If no match is found for the key, both elements of the pair return end( )
   if ( ( p2.first == s1.end( ) ) && ( p2.second == s1.end( ) ) )
      cout << "The set s1 doesn't have an element "<< "with a key less than 40." << endl;
   else
      cout << "The element of set s1 with a key >= 40 is: "<< *(p1.first) << "." << endl;
}

⌨️ 快捷键说明

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