回文の解決策を実装しようとしていたのですが、ロジックは正しいと思いますが、プログラムが無限ループに陥り、「Prep.exeが動作を停止しました」というエラーメッセージが表示されます。
int main()
{
string word, reverse;
cout << "Please enter a word to test for palindrome : ";
cin >> word;
cout << "Your word is: "<< word << endl;
int i = 0;
int size = word.length() - 1;
while (size >= 0)
{
reverse[i++] = word[size--];
//cout << reverse[i++];
}
cout << "The reversed word is: " << reverse << endl;
if (word == reverse)
cout << "It is palindrome" << endl;
else
cout << "It is not a palindrome" << endl;
}
whileループで何が間違っているのかわかりません。私はそれをデクリメントし続け、有効な終了条件を持っているのに、なぜそれがループでスタックするのですか?