Or operator not working

后端 未结 8 1213
一向
一向 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:10

     if (input.find("end" || "End") != std::string::npos)
     //             ^^^^^^^^^^^^^^
    

    The || operator is not being used correctly here. The righthand expression will return true because it is non-zero, then it will be returned. So the statement resolves to input.find("end"). You need to use two separate conditional statements there:

     if (input.find("end") != std::string::npos ||
         input.find("End") != std::string::npos)
    

提交回复
热议问题