C++判断是否为回文数

方框里面的内容为什么在for循环外呢?我把这段内容放到循环内以后输入回文数没有显示,这是为什么呀?

img

for的循环条件i <len/2,,达到len/2是回退出循环,执行不到if。
善用系统给我们提供的东西


#include<iostream>

#include<string>
using namespace std;
int main()
{
    string a;
    cin >> a;
    if (a == string(a.rbegin(), a.rend())) cout << "YES";
    else cout << "NO";
    return 0;
}