#include"stdafx.h"
#include <algorithm>
#include <functional>
#include <vector>
#include <iterator>
usingnamespaceStd
int_tmain (intARGC, _tchar* argv[])
{
//example of two-way access
Charst[ One] ="Abcdefghij";
vector<Char> A (St, St +Ten);
vector<Char>::iterator p = a.begin ();//defines a forward generic pointer and initializes
vector<Char>::reverse_iterator PS;//Justice inverse generic pointer
for(P = a.begin (); P! = A.end (); ++p)//Forward Access
{
cout << *p <<" ";
}
cout << Endl;
for(P = a.end (); P! = A.begin ();--p)//using a forward generic pointer to reverse-access
{
cout << * (P-1) <<" ";
}
cout << Endl;
for(PS = A.rbegin (); PS! = A.rend (); ++ps)//Using inverse generic pointer forward access, using the + + operation
{
cout << *ps <<" ";
}
cout << Endl;
for(; PS! = A.rbegin ();--ps)//reverse access using inverse generic pointers, using--operations
{
cout << * (PS-1) <<" ";
}
return0;
}
An improved method for forward and reverse cyclic reading of C + + generic pointers