我試圖做輸入字符串,這意味着迴文檢查的實例之後調用:終止拋出out_of_range
`"Anna"` returns `true`,
`"ada"` returns `true`,
`"1ada1"` return `true`
"ABJKkjBa"
返回true,
空間和符號,如」 [。 ];」不算數。只比較字母和數字。
這裏是我的程序:
int main()
{
string input;
getline(cin,input);
if(isPalindrome(input))
cout << "it is palindrome phase, or words." << endl;
else
cout << "it's not palindrome phase, or words." << endl;
return 0;
}
bool isPalindrome(string input)
{
string TemStore_1; //only letter, number will be store in here.
string TemStore_2; //storing TemStore_1 data other way around.
for(int i=0;i<input.length();i++)
{
if((input.at(i)<58) && (input.at(i)>47)) //catching number from 0-9
TemStore_1+=input.at(i);
if((input.at(i))<123 && (input.at(i)>96)) //catching letter from a-z
TemStore_1+=input.at(i);
if((input.at(i)<91) && (input.at(i)>64)) //catching letter from A-Z, and change it to a-z
{
input.at(i)+=32;
TemStore_1+=input.at(i);
}
}
for(int j=TemStore_1.length();j>-1;j--) //backwards writing the TemStore_1 into TEmStore_2
{
TemStore_2+=TemStore_1.at(j);
}
if(TemStore_1==TemStore_2)
return true;
else
return false;
}
在我得到了超出範圍的錯誤結束...不知道哪個部分出了問題..
可以請你發佈錯誤,因爲我明白了嗎? – 2014-10-20 20:31:23
因此,可能在(i)或在(j)正在訪問它不應該的東西? – 2014-10-20 20:31:30
所以在調試器中運行它,找出拋出異常和超出範圍的東西,找出它超出範圍的原因,並弄清楚它是如何到達那裏的。我們不需要。 – chris 2014-10-20 20:34:34