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