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

📄 chapter10-29.cpp

📁 C++STL程序员开发指南
💻 CPP
字号:
//文件名:CHAPTER10-29.cpp
#include <map>
#include <iostream>
#if _MSC_VER > 1020   // if VC++ version is > 4.2
   using namespace std;  // std c++ libs implemented in std
#endif
void main( )
{
   typedef map <int, int, less<int> > IntMap;
   IntMap m1;
   map <int, int> :: const_iterator m1_RcIter;
   typedef pair <int, int> Int_Pair;
   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );
   pair <IntMap::const_iterator, IntMap::const_iterator> p1, p2;
   p1 = m1.equal_range( 2 );
   cout << "The lower bound of the element with "<< "a key of 2 in the map m1 is: "
        << p1.first -> second << "." << endl;
   cout << "The upper bound of the element with "<< "a key of 2 in the map m1 is: "
        << p1.second -> second << "." << endl;
   // Compare the upper_bound called directly 
   m1_RcIter = m1.upper_bound( 2 );
   cout << "A direct call of upper_bound( 2 ) gives "<< m1_RcIter -> second << "," << endl
        << " matching the 2nd element of the pair"<< " returned by equal_range( 2 )." << endl;
   p2 = m1.equal_range( 4 );
   // If no match is found for the key, both elements of the pair return end( )
   if ( ( p2.first == m1.end( ) ) && ( p2.second == m1.end( ) ) )
      cout << "The map m1 doesn't have an element "<< "with a key less than 40." << endl;
   else
      cout << "The element of map m1 with a key >= 40 is: "<< p1.first -> first << "." << endl;
}

⌨️ 快捷键说明

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