天天看点

C++调用Python-1:hello world

#include "Python.h"
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
    Py_Initialize();
    if (!Py_IsInitialized())
    {
        cout << "初始化失败" << endl;
    }
    
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append('./')");
    PyRun_SimpleString("print('hello world')");
    
    Py_Finalize();
    return 0;
}