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

📄 chapter8-36.cpp

📁 C++STL程序员开发指南
💻 CPP
字号:
//文件名:CHAPTER8-36.cpp
#include <list>
#include <iostream>
#if _MSC_VER > 1020   // if VC++ version is > 4.2
   using namespace std;  // std c++ libs implemented in std
#endif
template <class T> class is_odd : public std::unary_function<T, bool> 
{
public:
   bool operator( ) ( T& val ) 
   {
   return ( val % 2 ) == 1;
   }
};
int main( ) 
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter, c2_Iter;
   c1.push_back( 3 );
   c1.push_back( 4 );
   c1.push_back( 5 );
   c1.push_back( 6 );
   c1.push_back( 7 );
   c1.push_back( 8 );
   cout << "The initial list is c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
   list <int> c2 = c1;
   //c2.remove_if( is_odd<int>( ) );
   c2.remove( 1);
   c2.remove( 3);
   c2.remove( 5);
   c2.remove( 7);
   cout << "After removing the odd elements, "
        << "the list becomes c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
   return 0;
}

⌨️ 快捷键说明

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