I have a question about comparing strings in C++. My code below is supposed to check if a word is a palindrome (spelled the same way forward and backwards). The problem is that my if statement (s1 == s2) never evaluates to true. I have the feeling that in memory these two strings are different, but I don't have any concrete proof. Any advice? Thanks!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1, s2;
cin >> s1;
for(int i = 0; i <= s1.size(); i++){
s2.push_back(s1[(s1.size() - i)]);
}
cout << s1 <<endl;
cout << s2 <<endl;
if(s1 == s2){
cout << "Correct" <<endl;
}
else {
cout << "Incorrect" <<endl;
}
return 0;
}