Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
advance.cpp
Go to the documentation of this file.
1
29#include <iterator> // for advance
30#include <iostream> // for cout, endl
31#include <list> // for list
32
33#include <examples.h>
34
35
36int main ()
37{
38 // Typedefs for convenience.
39 typedef std::list<long, std::allocator<long> > List;
40 typedef std::ostream_iterator<List::value_type,
41 char, std::char_traits<char> > os_iter;
42
43 // Initialize a list using an array.
44 const List::value_type arr [] = { 3, 4, 5, 6, 7, 8 };
45 List l (arr + 0, arr + sizeof arr / sizeof *arr);
46
47 // Declare a list iterator, s.b. a ForwardIterator.
48 List::iterator itr = l.begin ();
49
50 // Output the original list.
51 std::cout << "For the list: ";
52 std::copy (l.begin (), l.end (), os_iter (std::cout, " "));
53
54 std::cout << std::endl << std::endl
55 << "When the iterator is initialized to l.begin (),"
56 << "\nit points to " << *itr << std::endl;
57
58 // operator+ is not available for a ForwardIterator, so use advance.
59 std::advance (itr, 4);
60 std::cout << "\nAfter advance (itr, 4), the iterator points to "
61 << *itr << std::endl;
62
63 return 0;
64}
int main()
Definition advance.cpp:36