有人可以告诉我为什么这不起作用吗? 我要检查,如果一个词是回文(不使用reverse()方法)反转一个没有reverse()方法的字符串。我在做什么错
bool check(const string & s)
{
string temp;
int count = 0;
for (long i = s.size() - 1; i >= 0; i--, count++)
temp[count] = s[i];
cout << temp;
if (temp == s)
return true;
else
return false;
}
调整你的字符串'temp'到s'的'大小启动循环之前。 –
temp被声明为字符串,你正在使用它作为数组? –
“这不起作用”不是一个可接受的问题陈述。 –