chapter9-28.cpp

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

CPP
28
字号
//文件名:CHAPTER9-28.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 multiset<int, less<int> > IntSet;
   IntSet ms1;
   multiset <int> :: const_iterator ms1_RcIter;
   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );
   pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
   p1 = ms1.equal_range( 20 );
   cout << "The upper bound of the element with "
        << "a key of 20 in the multiset ms1 is: "<< *( p1.second ) << "." << endl;
   cout << "The lower bound of the element with "
        << "a key of 20 in the multiset ms1 is: "<< *( p1.first ) << "." << endl;
   // If no match is found for the key,
   // both elements of the pair return end( )
   if ( ( p2.first == ms1.end( ) ) && ( p2.second == ms1.end( ) ) )
      cout << "The multiset ms1 doesn't have an element "<< "with a key less than 40." << endl;
   else
      cout << "The element of multiset ms1 with a key >= 40 is: "<< *( p1.first ) << "." << endl;
}

⌨️ 快捷键说明

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