I am writing up a function that reverses the order of the string "rdd" to "ddr", when I run it I get an error that substring is out of range. Any help is appreciated!
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;
string reverse(const string & s);
int main() {
    cout << reverse("rdd") << endl;
}
string reverse(const string & s) {
    string rname(s);
    for (unsigned i = rname.size()-1; i >= 0; i--) {
        cout << rname[i];
    }
    return rname;
}
 
     
     
     
     
    