简体   繁体   English

c++ 使用大于等于运算符时出错

[英]c++ error when using greater than equal to operators

I am facing a error when compiling my c++ code, when hovering over it, it says error:- no operator ">=" matches these operands -- operand types are: std::__cxx11::string >= intC/C++(349).我在编译我的 c++ 代码时遇到错误,当将鼠标悬停在它上面时,它说错误:- no operator ">=" 匹配这些操作数——操作数类型是:std::__cxx11::string >= intC/C++(349 )。

the code goes like this, its a function in a structure, which takes an array variable from the same structure and runs a loop to check the values in that array is greater or equal to 999,代码是这样的,它是一个结构中的 function,它从同一结构中获取一个数组变量并运行一个循环来检查该数组中的值是否大于或等于 999,

ERROR IS ON THE LINE - if ((PowerChecker.cpower[a] >= 999)) I AM NOT ALLOWED TO COMPARE ARRAY错误在线 - 如果 ((PowerChecker.cpower[a] >= 999)) 我不允许比较数组

customers InputChecker(struct customers PowerChecker)
{
    for (int a = 0; a < 4; a++)
    {
        if ((PowerChecker.cpower[a] >= 999))
        {
            cout << "Please re-specify the power of your character" << PowerChecker.cpower[a] << endl;
            cout << "Power shoudl not Excced Limit 999 " <<endl;
        }
        
    }
    return (PowerChecker);
    
}

here is the image of error after compiling这是编译后的错误图像编译时的错误图像

EDIT: SOLVED编辑:已解决

As Peter and drescherjm wrote in the comments, it seems that you try to compare a string to an integer.正如 Peter 和 drescherjm 在评论中所写,您似乎尝试将字符串与 integer 进行比较。 You will need to convert the string first.您需要先转换字符串。 Many ways how to do this can be found here: How can I convert a std::string to int?在这里可以找到很多方法: 如何将 std::string 转换为 int?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM