我无法将 main()
参数与 const char*
字符串进行比较。
简单代码解释:
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
if(argc>1)
{
for (i=1;i<argc;++i)
{
printf("arg[%d] is %s\n",i,argv[i]);
if(argv[i]=="hello")
printf(" arg[%d]==\"hello\"\n",i);
else
printf(" arg[%d]!=\"hello\"\n",i);
}
}
return 0;
}
简单编译g++ test.cpp
。当我尝试执行它时,我看到下一件事:
>./a.out hello my friend
arg[1] is hello
arg[1]!="hello"
arg[2] is my
arg[2]!="hello"
arg[3] is friend
arg[3]!="hello"
我的代码有什么问题?
最佳答案
关于c++ - 主要参数处理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21454739/