This is my first semester of C++ programming. I need this function to output a whole string mirrored. Even with spaces like "This is a sentence". When I run it, it only reverses the first word. For example, "Aaron = noraA". Thank you.
#include <iostream>
using namespace std;
string sReverse(string s)
{
string r = "";
int i =s.length() -1;
while (i >= 0)
{
r += s[i];
i--;
}
return r;
}
Notice that the istream extraction operations use whitespaces as separators; Therefore, this operation will only extract what can be considered a word from the stream. To extract entire lines of text, see the string overload of global function getline.