Hi All,
I am trying to run my code based on the command line argument.
Following is the partial code:
I want to check if the user has mentioned any command line argument or not, one simple way is to check "argc".....but I just want to know how do we check it through "argv[1]". For example, if i write the following code:Code:int main(int argc, char *argv[]){ std::cout<<"******************************"<<std::endl; std::cout<<std::endl; std::cout<<"Method is: "<<argv[1]<<std::endl; // prints command line argument ......... .............. ................... }
It doesn't work, as compiler says empty character constant.Code:if(argv[1]==''){ //empty character std::cerr<<"Method Missing"<<std::endl; exit(1); }
If I use the following:
Then the compiler warns me of: comparison with string literal results in unspecified behaviorCode:if(argv[1]==""){ //string literal std::cerr<<"Method Missing"<<std::endl; exit(1); }
Can you guys suggest me, what is the best way.
Thanks.




Reply With Quote