我编写了一个检查回文的代码,但是它在命令提示符和在线编译器上出现了错误,但是我在不同的在线编译器上执行了该代码,它成功地编译并给出了理想的结果。错误是:palindrome.cpp:9:26: error:'size‘没有在这个作用域中声明
#include<iostream>
using namespace std;
int main()
{
string num_str = "";
cin >> num_str;
string new_str = "";
for(int x = (size(num_str)-1); x >= 0; x--){
new_str += num_str[x];
}
cout << (num_str == new_str ? "palindrome" : "Non-palindrome");
return 0;
}``` 发布于 2021-09-24 15:49:24
要获得字符串的大小,可以使用一个成员函数。更改这一行:
for(int x = (size(num_str)-1); ... )至
for(int x = num_str.size()-1; ... )此外,您可能应该包括:
#include <iostream>
#include <string>
// ...https://stackoverflow.com/questions/69317205
复制相似问题