I have the following code and I just can't seem to figure out a way to get the strings reversed here:
stringstream convert;
string y="";
string z="";
convert << x;
string::reverse_iterator rit;
y=convert.str();
int j=0;
for (rit = y.rbegin(); rit < y.rend(); rit++){
z[j] = *rit;
j++;
}
Can someone help me out with this? Thanks!
z.assign(y.rbegin(), y.rend());
Or you can do it upon construction:
std::string z(y.rbegin(), y.rend());
If you want to modify a string in place, use std::reverse:
std::reverse(y.begin(), y.end());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With