织梦CMS - 轻松建站从此开始!

罗索

用python 在c++计算数学表达式的例子

落鹤生 发布于 2010-04-26 22:02 点击:次 
#include stdafx.h #include Python.h #include iostream #pragma comment(lib,python22.lib) int _tmain( int argc,_TCHAR * argv[]) ... { Py_Initialize(); PyObject * module; PyObject * dict; PyObject * obj; long lval; PyRun_SimpleString( obj=(3*5)+8 ); mo
TAG:

  1. #include "stdafx.h" 
  2. #include "Python.h" 
  3. #include <iostream> 
  4.  
  5. #pragma comment( lib, "python22.lib" )     
  6.  
  7. int _tmain(int argc, _TCHAR* argv[]) 
  8.     Py_Initialize(); 
  9.     PyObject * module; 
  10.     PyObject * dict; 
  11.     PyObject * obj; 
  12.     long lval; 
  13.  
  14.     PyRun_SimpleString("obj = (3 * 5)+8"); 
  15.     module = PyImport_AddModule("__main__"); 
  16.     dict   = PyModule_GetDict(module); 
  17.     obj    =  PyMapping_GetItemString(dict, "obj"); 
  18.     if (obj != NULL) 
  19.     { 
  20.         lval = PyInt_AsLong(obj); 
  21.         printf("obj: %d ", lval); 
  22.     } 
  23.     else 
  24.     { 
  25.         printf("Object not found "); 
  26.     } 
  27.     return 0; 

 

(hardVB)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201004/9268.html]
本文出处:CSDN博客 作者:hardVB
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容