home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 May
/
VPR9705A.ISO
/
VPR_DATA
/
PROGRAM
/
CBTRIAL
/
SETUP
/
DATA.Z
/
DISTANCE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-14
|
781b
|
34 lines
#include<iterator>
#include<vector>
using namespace std;
int main()
{
//
// Initialize a vector using an array.
//
int arr[6] = {3,4,5,6,7,8};
vector<int> v(arr+0, arr+6);
//
// Declare a list iterator, s.b. a ForwardIterator.
//
vector<int>::iterator itr = v.begin()+3;
//
// Output the original vector.
//
cout << "For the vector: ";
copy(v.begin(), v.end(), ostream_iterator<int>(cout," "));
cout << endl << endl;
cout << "When the iterator is initialized to point to " << *itr << endl;
//
// Use of distance.
//
vector<int>::difference_type dist;
distance(v.begin(), itr, dist);
cout << "The distance between the beginning and itr is " << dist << endl;
return 0;
}