How to compare string with const char*?

前端 未结 6 1916
一生所求
一生所求 2021-02-19 06:20
#include 
#include 
#include 
#include 
using namespace std;
int main()
{
        string cmd;
        whil         


        
6条回答
  •  暖寄归人
    2021-02-19 07:05

    Just a few things to keep in mind, i am reiterating some of the suggestions that are worth repeating while(1) times.

    1. You are using C++, it is object oriented, i.e., Its best to combine together the data and the function that works on it. In this case use the string compare options provided by string class rather than strcmp.

    2. There is a logic error in your program, well it will compile, but i am afraid thats not what you want. if ( a == x && a == y ) this will always be false, as a cannot be both equal to x and y unless x=y, in your case clearly x!=y.

    Cheers, Pavan

提交回复
热议问题