gpt4 book ai didi

c++ - 从函数调用 C++ 程序?

转载 作者:行者123 更新时间:2023-11-30 04:43:28 25 4
gpt4 key购买 nike

所以我对 C++ 和一般编程还很陌生,我想弄清楚如何使用 this 中的代码我自己的程序里面的github程序。如何编写调用程序并返回结果的函数?

最佳答案

Here是对 std::system 的引用。有了它,您可以在 POSIX 系统上运行任何命令。

#include <cstdlib>
#include <fstream>
#include <iostream>

int main()
{
std::system("ls -l >test.txt"); // execute the UNIX command "ls -l >test.txt"
std::cout << std::ifstream("test.txt").rdbuf();
}

如果您需要其他平台(例如 Windows),请查看 boost process .

关于c++ - 从函数调用 C++ 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58269843/

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