Tag: args

主要参数处理问题

我无法将main()参数与const char*字符串进行比较。 简单的代码解释: #include 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” 我的代码有什么问题?