I need to create a program that allows a user to input a string and my program will check to see if that string they entered is a palindrome (word that can be read the same backwards as it can forwards).
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just compare the string with itself reversed:
This constructor of
stringtakes a beginning and ending iterator and creates the string from the characters between those two iterators. Sincerbegin()is the end of the string and incrementing it goes backwards through the string, the string we create will have the characters ofinputadded to it in reverse, reversing the string.Then you just compare it to
inputand if they are equal, it is a palindrome.This does not take into account capitalisation or spaces, so you’ll have to improve on it yourself.