Use a reverse iterator to display the string in reverse : string reverse « String « C++






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()
{
  string strA("This is a test.");

  string::reverse_iterator ritr;
  for(ritr = strA.rbegin(); ritr != strA.rend(); ++ritr)
    cout << *ritr;

  return 0;
}
  
    
  








Related examples in the same category

1.Reverse the order of all characters inside the string
2.Reversing a String and Finding its Length
3.Print characters read from keyboard in reverse order
4.Reversing an STL String
5.Reverse a string in place.