CHAPTER8-17.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
源码类别:

STL

开发平台:

C/C++

  1. //文件名:CHAPTER8-17.cpp
  2. #include <list>
  3. #include <iostream>
  4. #if _MSC_VER > 1020   // if VC++ version is > 4.2
  5.    using namespace std;  // std c++ libs implemented in std
  6. #endif
  7. int main( ) 
  8. {
  9.    using namespace std;
  10.    list <int> c1;
  11.    list <int>::iterator c1_Iter;
  12.    c1.push_back( 10 );
  13.    c1.push_back( 20 );
  14.    c1.push_back( 30 );
  15.    c1_Iter = c1.end( );
  16.    c1_Iter--;
  17.    cout << "The last integer of c1 is " << *c1_Iter << endl;
  18.    c1_Iter--;
  19.    *c1_Iter = 400;
  20.    cout << "The new next-to-last integer of c1 is "
  21.         << *c1_Iter << endl;
  22.    // If a const iterator had been declared instead with the line:
  23.    // list <int>::const_iterator c1_Iter;
  24.    // an error would have resulted when inserting the 400
  25.    cout << "The list is now:";
  26.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  27.       cout << " " << *c1_Iter;
  28.    return 0;
  29. }