0
What symbol/key word should i use to have a reverse output? Like garbage-> egabrag
4 Réponses
+ 3
There is a built-in reverse() function Defined in algorithm header file. You have to give string begin and string end As arguments to this function.
For example
#include <algorithm>
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s = "Reverse me";
reverse(s.begin(), s.end());
cout<<s;
return 0;
}
OUTPUT:
em esreveR
+ 2
If you are working with std::string class then you can use std::reverse() defined in <algorithm> header to reverse it.
If you are working with C style strings then I don't think there is a factory function to do this, and you have to do it manually.
https://en.cppreference.com/w/cpp/algorithm/reverse