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

前端 未结 4 1028
挽巷
挽巷 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条回答
  •  萌比男神i
    2021-01-28 18:41

    lastTwoChars is a string. You must compare it to a string, or at least a const char * or const char[].

    The expression lastTwoChars == 41 compares lastTwoChars to 41--an int. This is not defined behavior for a string.

    Instead, put 41 in quotes to make it a const char[] (specifically const char[3]):

     if (lastTwoChars == "41")
    

    It looks like you do this several times in your code.

提交回复
热议问题