Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8347004
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类: 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中调试成功.

阅读(1915) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~