[英]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 我如何使用C ++中的命令行参数检查条件,例如我得到了这样的代码
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. 带有参数hello,hi等,当我的argv [1] ==“ hello”时,我想执行一些语句。 This comparison is throwing an error char is incompatible with const char* Is there a better way to compare these arguments?
此比较将引发错误char与const char不兼容char *是否有更好的方法来比较这些参数?
'a' is an int (more accurately 1 byte integer) 'a'是一个整数(更准确地说是1个字节的整数)
"a" is a string “ a”是一个字符串
Replace 'a' with "a" 将“ a”替换为“ a”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.