gpt4 book ai didi

c++ - 如何识别.exe文件是否需要输入参数

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:22 25 4
gpt4 key购买 nike

某人如何识别他是否需要为 C++ 中的可执行文件放置输入参数。

您应该在代码中找到哪些命令才能知道需要哪些参数?

例如,如果您需要像这样运行它:hello.exe test.txt。但你不知道。

因此,您运行 hello 可执行文件,但它旁边需要一个文本文件。有人怎么能在代码中识别出需要这种参数??

编辑:我的源代码有这样的 mainint main(int argc,char *argv[]) 但参数到底是什么?

argc 和 argv 唯一出现的地方就是这一行。

 #ifdef PARALLEL            
Test.CVodeInit_parallel(states,startTime,argc,argv);
#else
Test.CVodeInit_serial(states,startTime);
#endif

最佳答案

例如 - 如果有人像这样运行您的代码:

hello.exe test.txt

那么argc就是2,argv[0] = "hello.exe", argv[1] = "test.txt"

但是如果他们像这样运行代码:

你好.exe

那么 argc 将为 1,argv[0] = "hello.exe"

这是你要问的问题吗?基本上 argc 是一个整数,告诉你 argv 数组中有多少个字符串

关于c++ - 如何识别.exe文件是否需要输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9299526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com