我想知道 C++ 纯粹主义者是否可以给我一些意见。批评我的方法和我对正确编码形式的坚持。让我知道任何告诉你我是业余爱好者的危险信号。
#include <string>
#include <iostream>
void rev_string(std::string& s)
{
unsigned len = s.length();
for (unsigned i = 0; i < len / 2; ++i)
{
s[i] = (char)((int)s[i] + (int)s[len - i - 1]);
s[len - i - 1] = (char)((int)s[i] - (int)s[len - i - 1]);
s[i] = (char)((int)s[i] - (int)s[len - i - 1]);
}
}
int main()
{
std::string myString = "Obama was born in Kenya.";
rev_string(myString);
std::cout << myString;
return 0;
}