Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
reverse_iterator.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, endl
30#include <vector> // for vector
31
32#include <examples.h>
33
34
35int main ()
36{
37 typedef std::vector<int, std::allocator<int> > Vector;
38
39 // Initialize a vector using an array.
40 const Vector::value_type arr[] = { 3, 4, 7, 8 };
41 const Vector v (arr + 0, arr + sizeof arr / sizeof *arr);
42
43 // Output the original vector.
44 std::cout << "Traversing vector with iterator: \n ";
45 for (Vector::const_iterator i = v.begin (); i != v.end (); ++i)
46 std::cout << *i << " ";
47
48 // Output the vector backwards.
49 std::cout << "\n\nSame vector, same loop, reverse_itertor: \n ";
50 for (Vector::const_reverse_iterator j (v.end ());
51 j != Vector::const_reverse_iterator (v.begin ()); ++j)
52 std::cout << *j << " ";
53
54 std::cout << std::endl;
55
56 return 0;
57}
#define i
Definition 17.names.cpp:126
#define v
Definition 17.names.cpp:138
#define j
Definition 17.names.cpp:127
std::vector< UserClass, std::allocator< UserClass > > Vector
int main()