No match for 'operator==' in a simple string code

前端 未结 4 988
挽巷
挽巷 2021-01-28 18:20

Writing a simple code and ran into a problem I\'m not sure how to deal with. I tried looking into it with a search but nothing I found was much help and everyone\'s answers wer

4条回答
  •  生来不讨喜
    2021-01-28 18:45

    Presumably, the error is complaining that you can't compare a string to a number. They are two different types, and unlike some languages there is no magic conversion (or comparison) between them.

    You want to compare with another string:

    if (lastTwoChars == "25")
    //                  ^  ^
    

提交回复
热议问题