python 调用C++,传递int,char,char*,数组和多维数组
2018-03-21 11:19
169 查看
//C++文件#include<iostream>using namespace std;//该文件名称:cpptest.cpp//终端下编译指令://g++ -o cpptest.so -shared -fPIC cpptest.cpp//-o 指定生成的文件名,-shared 指定微共享库,-fPIC 表明使用地址无关代码extern "C"{//在extern “C”中的函数才能被外部调用 int test(int int_test,char char_test,char *test_string,int int_arr[4],char char_arr2[2][2]) { cout<<"输出参数中的int型:"; cout<<int_test<<endl; cout<<"输出参数中的char型:"; cout<<char_test<<endl; cout << "输出参数中的字char*字符:"; cout<<test_string<<endl; cout << "输出参数中的int数组"; for(int x = 0;x< 4;x++){cout << int_arr[x]<<" ";} cout << endl; cout <<"输出参数中的二维数组:"; for(int x = 0;x<2;x++){ for(int y = 0;y<2;y++){ cout <<char_arr2[x][y] << " "; } } cout << endl; return 0; }} //py文件import ctypesmylib = ctypes.cdll.LoadLibrary("cpptest.so")char_p_test = bytes("中国","utf8")#汉字需用采用utf8编码int_arr4 = ctypes.c_int*4int_arr = int_arr4()int_arr[0] = 1int_arr[1] = 3int_arr[2] = 5int_arr[3] = 9char_arr2 = ctypes.c_char*2char_arr22 = char_arr2*2char_arr22a = char_arr22()char_arr22a[0][0] = b'a'char_arr22a[0][1]= b'b'char_arr22a[1][0] = b'c'char_arr22a[1][1] = b'd'mylib.test(9999,'a',char_p_test,int_arr,char_arr22a)
相关文章推荐
- python调用dll文件时传入参数是int*,返回值是char*,对传入的char*所指的内容的修改
- java调用python脚本并向python脚本传递参数
- python各种类型转换-int,str,char,float,ord,hex,oct等
- vs2010 unicode 下类型转换CString,char*,char,string,int,double
- VB调用C# DLL 传递数组参数问题
- CString,string,int ,long,double,char*,const char*,date等----留着备用
- 在VB中调用C/C++语言编写的dll,数组参数的传递
- (c++) int 转 string,char*,const char*和string的相互转换
- 用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!
- Android-调用本地方法传递数组参数/NDK-JNI开发实例(五)
- cout<<char数组名/数组指针"跟"cout<<int数组名/数组指针"的差别
- c++中的一些类型转换 : CString,string,int ,long,double,char*,const char*,date等
- 编写函数 void count(char a[],char w[][10],int n,int b[]).功能是:统计w指向的数组中的n个单词在a指向的字符串中各自出现的次数(将非字符字符看作单词分割
- sprintf_s实现int数组转换成char数组
- Mybatis调用PostgreSQL存储过程实现数组入参传递
- python 调用c++返回char*
- char、char*、char**数组(有图,非常清楚)good
- python各种类型转换-int,str,char,float,ord,hex,oct等
- strlen与sizeof计算char* 与char数组
- python 元组和字典中元素作为函数调用参数传递