//判断字符串是否是回文字符串(考虑大小写,空格和标点符号) bool palindrome1(string& str) { string ret; for (auto& c : str) { if (isalpha(c)) { if (isupper(c)) { ret.push_back(tolower(c)); } else { ret.push_back(c); } } } string target(ret.rbegin(), ret.rend());//翻转字符串 return target == ret; } #include <iostream> #include <string> using namespace std; int main() { string str; cout << "请输入一串字符(按'q'结束):"; while (getline(cin, str) && str != "q") { if (palindrome1(str)) { cout << "该字符串是回文字符串!\n"; } else { cout << "该字符串不是回文字符串!\n"; } } return 0; }标签:string,ret,bool,str,字符串,回文,函数 From: https://www.cnblogs.com/smartlearn/p/18023798