Or operator not working

后端 未结 8 1215
一向
一向 2020-12-12 07:44

When I enter start then the program outputs the else function even though I fulfilled the criteria, I have tried with && as well and it still didn\'t work. Any answe

8条回答
  •  孤街浪徒
    2020-12-12 08:06

    The argument of the function call

    input.find("end" || "End") 
    

    has type bool and means that addess of string literal "end" or/and address of string literal "End" is not equal to zero. It is obvious that the both string literals have addresses that are not equal to zero. So the call is equivalent to

    input.find(true) 
    

    The compiler finds an overloaded function find that is the most suitable for this argument. This function is

    find( charT, c, size_tipe pos = 0 );

    Value true is implicitly converted to value charT( 1 ) and the function tries to find char with value 1 in your string.

提交回复
热议问题