我有下一个简单的代码:
#include <Python.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *fout;
fout = freopen("stdout.txt", "w", stdout);
Py_Initialize();
PyRun_SimpleString("print('Message')");
Py_Finalize();
fclose(fout);
return 0;
}
我认为输出文件“stdout.txt”必须包含打印的消息,但它是空的。试图阅读有关 function的信息freopen()
,但我到处都能看到类似的例子。我也读了这个问题:
freopen not writing to the specified file
but can't understand what that solution's author means and how implementation this solution in code..