follow my heart...
分类: C/C++
2006-09-18 08:39:29
//必须要在执行程序所在目录中拷入python24.dll 文件
#i nclude
#i nclude
using namespace std;
//包含python库
extern "C" {
#i nclude
}
int main(int argc, char* argv[])
{
//初始化python
Py_Initialize();
//显示python版本及一些帮助信息
cout << "Python " << Py_GetVersion() << endl << endl << endl;
cout << "Type in some Python script. Type 'exit' to quit." << endl;
//执行一个内嵌的python语句
PyRun_SimpleString("print 1+2");
//开始处理
string input;
while(input != "exit"){
cout << ">> ";
getline(cin, input);
PyRun_SimpleString(input.c_str());
}
//结束
Py_Finalize();
return 0;
}
注:在连接中要加入-lpython24
在winxp+devcpp中调试成功.