Do you want to take the output of a python program and use it as input to a C++ program?
You could just use the shell for that:
python ./program.py | ./c_program
Do you want to execute a python program from within C++ and get the output back as a string?
There are probably better ways to do it, but here is a quick solution:
//runs in the shell and gives you back the results (stdout and stderr)
std::string execute(std::string const& cmd){
return exec(cmd.c_str());
}
std::string execute(const char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
if (result.size() > 0){
result.resize(result.size()-1);
}
return result;
}
std::string results_of_python_program = execute("python program.py");