gpt4 book ai didi

c++ - 如何在运行时将参数放入函数中?

转载 作者:太空狗 更新时间:2023-10-29 20:38:52 29 4
gpt4 key购买 nike

所以我在我的 C++ 程序中使用了 execlp。 execlp 的形式为“int execlp(const char *file, const char *arg0,...,const char *argn)”,这意味着它可以接受任意数量的参数。我只想知道有没有办法在运行时将参数放入这个函数中?由于参数是由用户提供的,我无法知道参数的确切数量。当然,我可以从一开始就选择一个大得离谱的数字,但这不会非常有效。我需要一种更有效的方法来允许我在运行时输入参数。

最佳答案

如果您不需要使用execlpexecvexecvp 是满足您要求的更好的函数。

来自 http://linux.die.net/man/3/execlp

The execv(), execvp(), and execvpe() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer.

关于c++ - 如何在运行时将参数放入函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30010692/

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