gpt4 book ai didi

PHP 系统()参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:36:21 24 4
gpt4 key购买 nike

我有以下代码执行C++程序输出它:

<html>
<head>
<title>C++</title>
</head>
<body>
<div><?php
system("app.exe", $out);
echo rtrim($out, "0");
?></div>
</body>
</html>

我怎样才能让它你可以将参数传递给c++程序,像这样说......

如果这是c++程序

#include <iostream>
#include <string>
int main(){
string input = getarg();//Not really a function, just one I kinda want to know
cout << input;
return 0;
}

我可以做这样的事情吗?

<html>
<head>
<title>C++</title>
</head>
<body>
<div><?php
system("app.exe arg=hello-world", $out);
echo rtrim($out, "0");
?></div>
</body>
</html>

不知道这个问题的很多部分,我可以执行程序但我只是需要传递参数。

最佳答案

您可以传递命令后以空格分隔的参数,例如 system("app.exe hello-world 2 3", $out);

在你的 C++ 程序中

 int main (int argc, char** argv) {
// argv[1] will be pointing to "hello-world"
// argv[2] => 2
// argv[3] => 3
}

关于PHP 系统()参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640414/

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