listtest7.cpp

来自「VC.net 的一些有用的技巧」· C++ 代码 · 共 36 行

CPP
36
字号
#include <list>
#include <algorithm>
#include <iostream>
using namespace std;
typedef list<int> LISTINT;

bool greater10 ( int value )
{
   return value >10;
}

int main( )
{
   list <int> L;
   list <int>::iterator Iter;
   list <int>::iterator result;
   
   L.push_back( 5 );
   L.push_back( 10 );
   L.push_back( 15 );
   L.push_back( 20 );
   L.push_back( 10 );

   cout << "L = ( " ;
   for ( Iter = L.begin( ) ; Iter != L.end( ) ; Iter++ )
      cout << *Iter << " ";
   cout << ")" << endl;   
   result = find_if( L.begin( ), L.end( ), greater10 );
   if ( result == L.end( ))
	   cout << "There is no element greater than 10 in list L."<< endl;
   else
      result++;
      cout << "There is an element greater than 10 in list L,"
           << " and it is followed by a "
           <<  *(result) << "." << endl;
}

⌨️ 快捷键说明

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