chapter9-30.cpp

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

CPP
30
字号
//文件名:CHAPTER9-30.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
void main( )
{
   multiset <int> ms1;
   multiset <int> :: const_iterator ms1_AcIter, ms1_RcIter;
   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );
   ms1_RcIter = ms1.lower_bound( 20 );
   cout << "The element of multiset ms1 with a key of 20 is: "<< *ms1_RcIter << "." << endl;
   ms1_RcIter = ms1.lower_bound( 40 );
   // If no match is found for the key, end( ) is returned
   if ( ms1_RcIter == ms1.end( ) )
      cout << "The multiset ms1 doesn't have an element "<< "with a key of 40." << endl;
   else
      cout << "The element of multiset ms1 with a key of 40 is: "<< *ms1_RcIter << "." << endl;
   // The element at a specific location in the multiset can be 
   // found using a derefenced iterator addressing the location
   ms1_AcIter = ms1.end( );
   ms1_AcIter--;
   ms1_RcIter = ms1.lower_bound( *ms1_AcIter );
   cout << "The element of ms1 with a key matching "
        << "that of the last element is: "<< *ms1_RcIter << "." << endl;
}

⌨️ 快捷键说明

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