C++ examples for STL:vector
Use a reverse iterator to show the contents of vector in reverse.
#include <iostream> #include <vector> using namespace std; void show(const char *msg, vector<char> vect); int main() {//ww w . ja v a2 s . c o m // Declare an empty vector that can hold char objects. vector<char> v; // Declare an iterator to a vector<char>. vector<char>::iterator itr; // Obtain an iterator to the start of v. itr = v.begin(); // Declare a reverse iterator. vector<char>::reverse_iterator ritr; // Use a reverse iterator to show the contents of v in reverse. cout << "Here is v in reverse: "; for(ritr = v.rbegin(); ritr != v.rend(); ++ritr) cout << *ritr << " "; cout << "\n\n"; return 0; }