0

C++ How to reverse a name.

I can't seem to figure out how I would reverse a name someone inputs. I know that i can use a for loop and maybe use strings to but I don't know in what order and stuff. could anyone help out.

21st Nov 2019, 10:53 PM
Terry Flores
Terry Flores - avatar
4 Respostas
+ 3
#include <iostream> #include <string> #include <algorithm> // to get the reverse function using namespace std; int main() { string mystring = "hello world"; reverse(mystring.begin(), mystring.end()); cout << mystring; return 0; }
21st Nov 2019, 11:12 PM
rodwynnejones
rodwynnejones - avatar
+ 1
string mystring = "just some rubbish"; string rev_mystring = ""; for(int x = mystring.length()-1; x > -1; x--) rev_mystring+=mystring[x]; cout << rev_mystring;
23rd Nov 2019, 8:40 PM
rodwynnejones
rodwynnejones - avatar
0
But is there a way without using the reverse function? Only using string, and For loop.
23rd Nov 2019, 2:56 PM
Terry Flores
Terry Flores - avatar
0
Thank you
26th Nov 2019, 4:26 PM
Terry Flores
Terry Flores - avatar