I'm trying to implement a simple command line program that takes three arguments and prints them on the linux terminal
(我正在尝试实现一个简单的命令行程序,该程序需要三个参数并将其打印在linux终端上)
For example:
(例如:)
>c++ exec.cpp
>./a 32 + 32
Should print out contents like this
(应该打印出这样的内容)
32
(32)
+
(+)
32
(32)
But the program is looping indefinitely
(但是程序无限循环)
I've implemented a check for argc Like this
(我已经实现了对argc的检查,就像这样)
if(argc!=3) {
cout << "Exit" << endl;
return -9999;
}
In case the argument count is 3
(如果参数计数为3)
These lines of code should be executed
(这些代码行应执行)
else {
for(int i=0;i<argc;i++){
cout << argv[i] << endl;
}
}
But as I explained before the program loops indefinitely
(但是正如我在程序无限循环之前解释的那样)
EDIT: Since I was asked to post the entire code here it is
(编辑:因为我被要求在这里发布整个代码)
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(int argc,char* argv[]) {
if(argc!=3) {
cout << "Exit" << endl;
return -9999;
}
else {
for(int i=0;i<argc;i++){
cout << argv[i] << endl;
}
}
}
EDIT 2: Issue still not solved and I'm worried that if I post another question like this I'll be downvoted to oblivion I really need a solution here and I'm not sure what to do
(编辑2:问题仍然没有解决,我担心如果我发布这样的另一个问题,我将被否决了,我真的需要一个解决方案,我不确定该怎么做)
ask by Ammar translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…