chapter9-5.cpp

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

CPP
27
字号
//文件名:CHAPTER9-5.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( )
{
   set <int> s1;
   set <int> :: iterator s1_Iter;
   set <int> :: const_iterator s1_cIter;
   s1.insert( 1 );
   s1.insert( 2 );
   s1.insert( 3 );
   s1_Iter = s1.end( );
   s1_Iter--;
   cout << "The last element of s1 is " << *s1_Iter << endl;
   s1.erase( s1_Iter );
   // The following 3 lines would err because the iterator is const
   // s1_cIter = s1.end( );
   // s1_cIter--;
   // s1.erase( s1_cIter );
   s1_cIter = s1.end( );
   s1_cIter--;
   cout << "The last element of s1 is now " << *s1_cIter << endl;
}

⌨️ 快捷键说明

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