gpt4 book ai didi

c++ - 在 system() 中使用参数 char argv[]

转载 作者:行者123 更新时间:2023-12-02 00:08:17 25 4
gpt4 key购买 nike

我需要从我的 C++ 代码执行 Perl 脚本。这是通过 system() 完成的。
现在我需要从代码中传递第二个参数:

int main(int argc, char * argv[])

像这样进入我的系统():

char *toCall="perl test.pl "+argv[1];
system(toCall);

现在它会带来错误:“‘const char [14]’和‘char**’类型的操作数对二进制‘operator+’无效”

我做错了什么?

最佳答案

使用std::string,例如

std::string const command = std::string( "perl test.pl " ) + argv[1];
system( command.c_str() );

您不能添加两个原始指针。

但是 std::string 提供了 + 运算符的重载。

关于c++ - 在 system() 中使用参数 char argv[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674721/

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