有更高端的方法,但是还没有去尝试。
如何实现 C/C++ 与 Python 的通信?
https://www.zhihu.com/question/23003213
这里采用一种简单的方式,脚本上运行python代码,然后捕获屏幕上的输出
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
FILE *in;
char buff[512];
string c = "/**/**/test.py"; //python脚本的路径
cout<<c<<endl;
if(!(in = popen(c.c_str() , "r"))){
return 1;
}
while(fgets(buff, sizeof(buff), in)!=NULL){
cout << buff; //捕获屏幕的输出
}
pclose(in);
return 0;
}