To reverse a string in C++, we only require to take a string as input from the user and extract each character of the original string from back to front and concatenate into another string again and again until all the characters are added in the backward direction.

Reverse a string in C++ Program

Steps to Reverse a String

  1. Take a string as input in str
  2. Run a for loop from str.length() to 0
  3. Concatenate the character into rev as rev = rev + str[loop Index]
  4. When out of the loop. Print the Reversed string rev

C++ Program

Tip: Use getline for getting string input (space inclusive) from the user. On using only cin stream the words after first space will not be taken as input.


Reverse a string in C++

That’s all we need to write to reverse a string using C++ programming language. If you have any doubts then do comment below.

Leave a Reply