I am writing a function for a class to reverse a string using recursion. I have a semi-functioning piece of code but it has an issue where it drops the last character to be printed on screen. It has to use the prototype "void reverse(string & letters);" so I can only take one input. It's probably a simple fix, but I can't see what's going wrong.
void reverse(string & letters){
if (letters.size() == 0){
return;
}
string t = letters.substr(1);
reverse(t);
cout << letters[0];
}
Input examples - Like / giant Output examples - eki / tnai