home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / ADVANCE.CPP < prev    next >
Text File  |  1997-02-14  |  805b  |  33 lines

  1.  #include <iterator>
  2.  #include <list>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize a list using an array.
  10.    //
  11.    int arr[6] = {3,4,5,6,7,8};
  12.    list<int> l(arr+0, arr+6);
  13.    //
  14.    // Declare a list iterator, s.b. a ForwardIterator.
  15.    //
  16.    list<int>::iterator itr = l.begin();
  17.    //
  18.    // Output the original list.
  19.    //
  20.    cout << "For the list: ";
  21.    copy(l.begin(),l.end(),ostream_iterator<int>(cout," "));
  22.    cout << endl << endl;
  23.    cout << "When the iterator is initialized to l.begin(),"
  24.         << endl << "it points to " << *itr << endl << endl;
  25.    //
  26.    // operator+ is not available for a ForwardIterator, so use advance.
  27.    //
  28.    advance(itr, 4);
  29.    cout << "After advance(itr,4), the iterator points to " << *itr << endl;
  30.  
  31.    return 0;
  32.  }
  33.