[Solved] How to print string backward in C++? [closed]


Your initial array index points to \0, you need something like –

for(int i=size-1; i>=0; i--) // <-- like this

or

for(int i=size; i>0; i--)
{
  cout<<input[i-1]; // <-- like this
}

or you could use reverse

#include <algorithm> // <-- add this include
std::reverse(input.begin(), input.end()); // <-- reverse the input string.

6

solved How to print string backward in C++? [closed]