home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
REV_ITR.CPP
< prev
next >
Wrap
Text File
|
1997-02-28
|
796b
|
34 lines
#include <iterator>
#include <vector>
using namespace std;
int main ()
{
//
// Initialize a vector using an array.
//
int arr[4] = {3,4,7,8};
vector<int> v(arr+0, arr+4);
//
// Output the original vector.
//
cout << "Traversing vector with iterator: " << endl << " ";
for(vector<int>::iterator i = v.begin(); i != v.end(); i++)
cout << *i << " ";
//
// Declare the reverse_iterator.
//
vector<int>::reverse_iterator rev(v.end());
vector<int>::reverse_iterator rev_end(v.begin());
//
// Output the vector backwards.
//
cout << endl << endl;
cout << "Same vector, same loop, reverse_itertor: " << endl << " ";
for(; rev != rev_end; rev++)
cout << *rev << " ";
return 0;
}