问题是什么?“美化”/评论问题代码
如果在其他语句和else语句不起作用的情况下运行if语句,则返回3。
你是什么意思“它不工作”?
int handleArgs(int argc, char *argv[]) {
int x = 0;
if (argc <= 1) {
return x;
}
x = 1;
for (int i = 1; i < argc; i++) {
string argument = argv[i]; // Convert argument to string
if (argument=="-v" || argument=="--version") { //*** If user asks for version info ***\\
cout << "\nYou are running \n Dev0.0.0" << endl;
} else if (argument == "-a " || argument == "--admin") { //*** If user tries to open console ***\\
cout << "\nSorry, console feature currently unavailable" << endl;
} else if (argument=="-h" || argument=="--help") { //*** If user asks for help ***\\
cout << "\nUsage: " << argv[0] << " -[switch] argument(s)\n";
cout << " -a, --admin Open console view. Requires password\n";
cout << " -v, --version Print version and exit\n";
cout << " -h, --help Print this message and exit\n" << endl;
} else {
cout << " Is you dumb?\nIncorrect syntax/argument(s)\n '" << argv[0] << " --help' for help." << endl;
}
}
}
return x;
} 具体来说,if(condition)
从不执行,即使条件为真。
第一个else if(condition)
也不会执行。
如果为true,则执行第二个else if
语句。
的else
如果是别的时候真实,
- 如果声明是真实的执行。
- 1st else if语句为true。
- 这些陈述都不是真实的。
- 如果2nd else if语句为true,则不适用。
摘要
基本上,它就像if
和第一else if
不存在。
编辑:如果Else语句不工作C++
粘贴源代码在这里。 –
@BenVoigt替换链接? – Gabe
是的,就像MikeCAT一样。链接可能导致病毒和东西,短代码片断要好得多。 –