unsigned int l = str.length();
tmp.reserve(l);
for(auto *end = &str[l-1]; *end >= str[0]; --*end) {
tmp += *end;
}
cout << tmp;
}
Is this a good way to reverse a string? Or is there a better way?
Note that I am just doing what I remember from the book(which I've just read(without any good practice) this summer), so I may have written stupid things.
Actually I don't reverse, I know. But this is just a test
Yesterday I was having a trouble with int/uint so I decided to do this.
the exit condition seems funny
It would be a good way if it was not undefined behaviour that fails on all architectures ever made by IBM or on any place that doesn't guarantee that char and unsigned char behave the same
But I still prefer string reversed{original.rbegin(), original.rend()}; When I want to go original
Обсуждают сегодня