anu
anu

Reputation: 15

conditional check for command line arguments in c++

How can me check for a condition using command line arguments in C++, for example I got a code like this

    int main(int argc, char* argv[]) { 

     if (strcmp(argv[1] , 'a')==0)
     {
         cout<<"something"<<endl;
     }
 }

with the arguments hello, hi etc., when my argv[1] == "hello", I want to execute some statements. This comparison is throwing an error char is incompatible with const char* Is there a better way to compare these arguments?

Upvotes: 0

Views: 814

Answers (1)

zar
zar

Reputation: 12227

'a' is an int (more accurately 1 byte integer)

"a" is a string

Replace 'a' with "a"

Upvotes: 3

Related Questions