C++ 回文算法 - 无法与'operator<'匹配
C++ Palindrome algorithm - No match for 'operator<'
我的下面C palindrome agorithm实现会导致以下错误:
"操作员&lt;"无匹配(操作数类型是'std :: basic_ostream&lt; char>'and'&lt;未解决的超载函数类型>'(
错误发生在结束else
线上。
#include <iostream>
using namespace std;
int main()
{
cout << "Write a number to check if its palindrome" << endl;
int a;
cin >> a;
int z = a;
int b;
int c;
while (a > 0) {
b = a % 10;
c = (c * 10) + b;
a = a / 10;
}
if (z == c) { cout << "This is a palindrome" << endl; }
else { cout << "This is not a palindrome" < endl; }
return 0;
}
我有以上错误
最后一个
<endl;
必须是
<<endl;
请小心阅读错误消息。他们在发生错误的线路中给出线号和字符位置。
我可以发誓我看了10次。
如果您要完美地格式化代码,您会很快找到错误。例如
#include <iostream>
using namespace std;
int main() {
cout << "Write a number to check if its palindrome" << endl;
int a;
cin >> a;
int z = a;
int b;
int c;
while (a > 0) {
b = a % 10;
c = (c * 10) + b;
a = a / 10;
}
if (z == c) {
cout << "This is a palindrome" << endl;
} else {
cout << "This is not a palindrome" < endl;
}
return 0;
}
为什么它向我表明该数字不管我是什么 放入它将很有用
您在循环之前不要初始化c
。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 基于ELO的团队匹配算法
- 没有用于初始化C++中的变量模板的匹配构造函数
- 呼叫运营商<<临时
- 调用'begin(int [n])'没有匹配函数
- 将模板与类模板扣除占位符参数匹配
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 功能样式转换从 'int' 到 'ItemType' 的匹配转换
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- <<操作员在下面的行中工作
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- Qt SQLite没有查询或参数计数不匹配
- 模板参数推导失败,函数参数/参数不匹配
- 错误 没有与参数列表匹配的重载函数"getline"实例
- 在使用累加时,C++中的运算符+不匹配
- 错误:调用'getline'没有匹配函数
- 没有匹配的“运营商&lt;&lt;”
- C++ostream:没有运算符匹配<<&应在'&'代币
- 错误:没有匹配'运算符<<"在'std::cout