ZBLOG

error: no match for ‘operator>’ (operand types are ‘const std::vector’ and ‘float’) 847 | xc[i] = *std::max_element(pred.begin() + 4, pred.begin() + mi) >innerpv->conf_thresh; | ...

错误提示显示,在比较 std::vector<float> 类型的对象 pred 中的元素和 float 类型的值时,发生了错误。这是因为 std::max_element() 返回一个迭代器,而不是一个单个值。

要解决此问题,你可以将 std::max_element() 的结果与所需的阈值进行比较。下面是修正后的示例代码:

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector<float> pred = {1.2, 3.4, 0.8, 5.6};
    float conf_thresh = 2.0;

    auto max_it = std::max_element(pred.begin() + 4, pred.end());
    
    if (max_it != pred.end() && *max_it > conf_thresh) {
        std::cout << "Max element is greater than the threshold" << std::endl;
    } else {
        std::cout << "Max element is not greater than the threshold" << std::endl;
    }

    return 0;
}

在上述代码中,我们使用 <algorithm> 头文件中的 std::max_element() 函数来找到向量 pred 中特定范围内的最大值。然后,我们将该最大值与阈值进行比较,并根据结果输出相应的消息。

请确保在实际使用时适当替换向量名称和阈值,并根据需要调整范围参数(在本例中是从第五个元素开始)。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=14885

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?