cppintermediate12 minutes
Reverse a String Without Built-Ins
Reverse a string manually without using built-in reverse helpers.
Challenge prompt
Write a C++ function that takes a string and returns it reversed without using a built-in reverse function.
Guidance
- • Use a loop from the end of the string to the beginning.
- • Build a new result string.
- • Return the final reversed string.
Hints
- • Start at index length - 1.
- • Append characters one by one to a new string.
Starter code
#include <string>
using namespace std;
string reverseString(string text) {
// your code here
}Expected output
reverseString("code") should return "edoc".
Core concepts
stringsloopsindexing
Challenge a Friend
Send this duel to someone else and see if they can solve it.