c++ - 错误: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<='

标签 c++ syntax-error

我的代码:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while( t-- ) {
        int n, x = 0;
        cin >> n;
        if(n % 2 == 0)
            cout << n/2 <<" "<< n/2 << endl;
        else
            int min = INT_MAX;
        for(int i = 1; i*i <= n; i++) {
            if(( n-i) % i == 0) {
                int d = (n-i) / i;
                if(d <= min) {
                    min = d;
                    x = i;
                }
            }
        }
        cout << x <<" "<< n-x <<endl;    
    }
    // your code goes here
    return 0;
}
该代码给出了一些我无法处理的典型错误。
请任何人帮我修复它。

C:\Users\HP\Desktop\Code\hello.cpp:21:20: error: invalid operands of types 'int'
and '' to binary 'operator<=' 21 | if(d<=min) | ~^~~~~

最佳答案

问题是您错过了{}情况下的else:

else
    int min=INT_MAX;
    for(int i=1;i*i<=n;i++)
因此,int min的范围仅限于定义它的单行。在if(d<=min)中,编译器会改为看到std::min()函数模板(这是因为您不建议使用using namespace std;)。

关于c++ - 错误: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<=' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65419045/

相关文章:

mysql - 创建删除触发器时的MySQL语法错误

mysql - 为什么我的最高薪水查询有语法错误?

c++ - Remove_If 字符串不区分大小写

c++ - 使用 bzip boost iostream - 未解析的符号

c++ - 你能做一个 C++ 泛型函数吗?

javascript - 未捕获的 ReferenceError : lookup is not defined at HTMLButtonElement. onclick

c++ - 模板-无法将函数定义与现有声明c++匹配

c++ - 面向对象的C++多线程

c++ - 在 if(指针)条件内递增指针

php - Mysql 在尝试运行更新请求后显示错误