#include #include #include "SillyT.h" using namespace std; typedef vector AVecT; void PrintList(const vector & v); int main() { int k; vector myVec; vector::iterator i; vector::const_iterator ci; vector::reverse_iterator ri; vector::const_reverse_iterator cri; for(k=0; k < 10; k++ ) { myVec.push_back(SillyT()); myVec[k].Int(k); myVec[k].String("Item Number " + to_string(k)); } // a forward iterator cout << "The forward list " << endl; for (i=myVec.begin(); i != myVec.end(); i++) { cout << "Offset: " << i - myVec.begin(); cout << "\t intValue = " << i->Int() << ", stringVal = " << i->String() << endl; } cout << endl << endl; // a reverse iterator. cout << "The Reverse List " << endl; for(ri = myVec.rbegin(); ri != myVec.rend(); ri++) { cout << "Offset: " << ri - myVec.rbegin(); cout << "\t intValue = " << ri->Int() << ", stringVal = " << ri->String() << endl; } // changing the values. for (i = myVec.begin(); i != myVec.end(); i++) { i->Int(i->Int()+10); } cout << endl << endl; cout << "After the change " << endl; PrintList(myVec); /* // changing the values. for (ci = myVec.begin(); ci != myVec.end(); ci++) { ci->Int(i->Int()+10); } */ cout << endl << endl; cout << "Moving both directions " << endl; i = myVec.begin() + myVec.size()/2; cout << "i points to " << i->Int() << " " << i->String() << endl; i++; cout << "i points to " << i->Int() << " " << i->String() << endl; i-=2; cout << "i points to " << i->Int() << " " << i->String() << endl; cout << "Using the begin() and end() functions " << endl; cout << endl << endl; // the begin(), end(), .. functions from the stl. for(i = begin(myVec); i != end(myVec); i++) { cout << i->String() << endl; } cout << endl << endl; // boom i = end(myVec); i += 1000; cout << " 1000 past the end, intVal = " << i->Int() << " stringVal = \"" << i->String() << '"' << endl; i->String("hello"); return 0; } /* void PrintList(const vector & v){ vector::iterator i; for (i = v.begin(); i != v.end(); i++) { cout << "Offset: " << i - v.begin(); cout << "\t intValue = " << i->Int() << ", stringVal = " << i->String() << endl; } return; } */ void PrintList(const vector & v){ vector::const_iterator i; for (i = v.cbegin(); i != v.cend(); i++) { cout << "Offset: " << i - v.cbegin(); cout << "\t intValue = " << i->Int() << ", stringVal = " << i->String() << endl; } return; }