我试图通过 main 传递参数,它工作正常,然后我检查传入的参数是否包含正确的格式/值。但是,即使我通过了正确的格式它仍然显示有问题,这里是代码:
int main(int argc, char* argv[]) {
/* Check if arguments are being passed through */
if(argc == 1){
cout << endl << "--- ERROR ---" << endl;
exit(0);
}
/* Check if the first argument contains the correct data */
string file_name = argv[1];
/* Handle operation */
string operation = argv[2];
if(operation != "-t" || operation != "-r")
{
cout << "Something is not right";
}
}
如果我这样做:cout << operation;
那么结果将是:-t
当我运行应用程序时通过 -t。
谁能建议我哪里出错了?
更新:
我将传递这些论点:
./main something.wav -t
我期待if语句:
if(operation != "-t" || operation != "-r")
{
cout << "Something is not right";
}
返回负数,因为我输入的值是 -t