Reversing a String and Finding its Length : string reverse « String « C++






Reversing a String and Finding its Length

  
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main( )
{
   string adage( "this is a test" );
   cout << adage;

   cout << adage.length() << " letters";

   // equivalent of strrev()
   reverse( adage.begin(), adage.end() );
   cout << "\n\nReversed string: " << adage;
   cout << "\nThe reversed string has " << adage.length() << " letters";
}
  
    
  








Related examples in the same category

1.Reverse the order of all characters inside the string
2.Print characters read from keyboard in reverse order
3.Reversing an STL String
4.Reverse a string in place.
5.Use a reverse iterator to display the string in reverse