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

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

我下面的 C++ 回文算法实现导致以下错误:

No match for 'operator<' (operand types are 'std::basic_ostream< char >' and '< unresolved overloaded function type >')

错误发生在结尾的 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;
}

I got the above error

最后一个

<endl;

必须

<<endl;

仔细阅读错误信息。他们在发生错误的行中给出行号和字符位置。

I could have sworn I looked at the code 10 times.

如果您能完美地格式化您的代码,您会很快发现错误。例如

#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;
}

why it shows me that the number is not a palindrome no matter what I put in it would be useful

您在循环之前没有用零初始化 c