I have a for loop that returns the user's input backwards. They enter a string, and the loop reverses it. Here's what it looks like:
string input; //what user enters
const char* cInput = input.c_str(); //input converted to const char*
for(int i = strlen(cInput) - 1; i >= 0; i--)
cout << input[i]; //Outputs the string reversed
Instead of having cout << input[i], how can I set input[i] as the value of a new string? Like I want to have a string called string inputReversed and set it equal to input[i].
In other words, if input == hello, and input[i] == olleh, I want to set inputReversed equal to olleh.
Is this doable? Thanks!
std::string::sizeinstead of converting to aconst char*and usingstrlen.