问题描述
我想写一个像这样的控制台应用程序:
i want to write to a console application that works like that :
<br />
reza -m <br />
做得很好,
does a big job,and
<br />
reza -n<br />
做另一项大工作,但与以前的工作完全无关.等等
我不是说如何识别输入的参数,而是我要写这些工作?
我应该将它们编写为可执行程序并通过主程序调用它们吗?
does another big job but totally unrelated to previous job.and so on
i don''t mean how to recognize which argument entered,i mean how to i write these jobs?
should i write them as an executable program and call them via the main program? or another ways?
推荐答案
int main(int argc, char **argv);
int main(int argc, char *argv[]);
//Windows-only
int main(int argc, char **argv, char **envp);
//Apple-only:
int main(int argc, char **argv, char **envp, char **apple);
函数参数argc
和argv
的实际值将从加载并传递给系统的客户实际输入的命令行中获取(直接从脚本,Shell,Windows * .lnk文件等获取).您的入口点功能.您的应用程序代码应使用它们.解析命令行参数以找出选项.
注意:您的应用程序代码提供的入口点"功能可以具有不同的名称,甚至可以具有不同的签名.当您在内部使用某些框架定义main
并调用应用程序应提供的某些其他函数(例如_tmain(int argc, _TCHAR* argv[])
时,可以在其中使用不同的字符类型,具体取决于编译选项)时,可能会发生这种情况.无论如何,这个想法是相同或非常接近的.
The actual values for the function arguments argc
and argv
will be taken from the command line actually entered by the customers (directly for from script, Shell, Windows *.lnk file, etc.) by the system loaded and passed to your entry-point function. You application code should use them; parse the command line parameters to figure out the options.
Note: The "entry-point" function supplied by your application code can have different name and even somewhat different signature. It might happen when you are using certain framework defines main
internally and calls some other function (such as _tmain(int argc, _TCHAR* argv[])
where you can use different character types, depending on compilation option) which your application should supply. The idea is the same or very close, anyway.
这篇关于具有不同参数的控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!