问题描述
如何在main函数中调用并在main函数外部定义的函数中使用命令行参数。即使我可以将它们作为参数传递。但是,如果我这样做...它让我传递了许多论点。所以,请让我知道如何在另一个函数中获取cmnd行参数,而不将它们作为参数传递给函数。
您可以实现一个全局单例对象,该对象包含命令的副本
行参数。 main()函数应该做的第一件事就是创建一个单独的
实例。所有其他函数都可以访问实例以获取
命令行参数的值。
亲切的问候,
Jos
主要功能的原型是
Hi,
How do i use command line arguments in the function which is called in main function and defined outside the main function.Even though,i can pass them as arguments..but if i do that...it makes me to pass many arguments.So,please let me know how do i fetch the cmnd line arguments in another function without passing them as parameters to the function.
You could implement a global singleton object that holds a copy of the command
line arguments. The first thing a main() function should do is create such a single
instance. All other functions can access the instance for the value(s) of the
command line arguments.
kind regards,
Jos
The prototype for the main function is
这篇关于关于在main func中定义的另一个函数中命令行参数的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!