C++ How To Check if a String Is a Palindrome
Check if a String Is a Palindrome
A palindrome is a word that is the same forward and backward, like "level". Reverse the string, and compare it with the original:
Example
string text = "level";
string reversed = text;
reverse(reversed.begin(), reversed.end());
if (text == reversed) {
cout << text << " is a palindrome";
} else {
cout << text << " is not a palindrome";
}
Explanation:reversed starts as a copy of text, and is then reversed.
If both strings are equal, the word is a palindrome.