#includebool isPalindrome(const std::string& str) { for (int i = 0; i < str.length() / 2; i++) { if (str[i] != str[str.length() - i - 1]) { return false; } } return true; }
std::string str1 = "racecar"; bool isPalindrome1 = isPalindrome(str1); // isPalindrome1 == true std::string str2 = "hello"; bool isPalindrome2 = isPalindrome(str2); // isPalindrome2 == false std::string str3 = "level"; bool isPalindrome3 = isPalindrome(str3); // isPalindrome3 == trueThe isPalindrome function does not require any external package or library. It is implemented using standard C++ string and loop operations.