Write your question here.
I have a feeling that i've made some miscalculation here. I was certain that I could reverse a string via implementing the following solution;
int j=7;
int main ()
{
string FirstReverse = "reverse";
cout << FirstReverse << endl;
for (unsignedint i=0; i < FirstReverse.size(); ++i)
{
FirstReverse[i]=FirstReverse[--j];
}
cout << FirstReverse << endl;
return 0;
}
unfortunately, my resulting output is as follows;
reverse
esrerse
I'm convinced that i've misunderstood the effect that would come about by pairing a decreasing variable with an increasing one, and am wondering if anyone can help me identify alternative solutions, or help me understand what went wrong with this one.
Well, you could easily create a temporary variable to hold the value at FirstReverse[i], so that when you switch it with FirstReverse[FirstReverse.length - i - 1], you can replace the other variable with what was originally in FirstReverse[i].