#include <bits/stdc++.h>
using namespace std;
int judge_palindrome(string s)
{
string tmp=s;
std::reverse(tmp.begin(), tmp.end()); //tmp 和 t 是 s的翻转
string t(tmp); //构造新串 t
// return !!t.compare(s); //和原串进行比较
return t==s;
}
int main()
{
string s="goog";
if(judge_palindrome(s)) cout<<" 是回文串"<<endl;
else cout<<" 不 是回文串 "<<endl;
return 0;
}string 对象下的系列函数学习
原文:http://wzsts.blog.51cto.com/10251779/1837301