C++ 回文算法 - 无法与'operator<'匹配

C++ Palindrome algorithm - No match for 'operator<'

本文关键字:lt 匹配 operator 算法 回文 C++      更新时间:2023-10-16

我的下面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