C++ examples for STL:string
Use a reverse iterator to display the string in reverse
#include <iostream> #include <string> #include <cctype> #include <algorithm> #include <vector> using namespace std; int main()//from w w w . j a v a 2 s. c o m { string strA("This is a test. another test test test"); // Create an iterator to a string. string::iterator itr; // Use a reverse iterator to display the string in reverse. cout << "Display a string in reverse using a reverse iterator.\n"; string::reverse_iterator ritr; for(ritr = strA.rbegin(); ritr != strA.rend(); ++ritr) cout << *ritr; cout << "\n\n"; return 0; }