如何在 C++ 中终止 运行 程序

How to terminate a running program in c++

我用 C++ 编写了一个程序,我将其称为

system("C:\xampp\xampp-control.exe");
至 运行 xampp 控制面板。当我运行编译后的程序时,运行很顺利,只是我写的程序还是运行ning。 XAMPP 控制面板启动后,我想终止该程序。可能做什么?非常感谢任何帮助。

您可以用 exec 调用的应用程序替换您的应用程序。

// Note: this waits for the exectued program to finish
// before the call to `system()` returns.
system("C:\xampp\xampp-control.exe");

// You can replace the current processes with the one you
// are starting like this.
execl("C:\xampp\xampp-control.exe", "xampp-control.exe");
// If this returns the applicaion failed to start.
std::cerr << "Failed to start application\n";
exit(1);