Swig: convert return type std::string to java byte[]

99封情书 提交于 2019-12-11 06:45:16

问题


I have a C++ method that returns a std::string. I am using SWIG and I want to add logic to SWIG to make the std::string that is returned, be received in Java as a byte[].

If this is possible, how can I do this?

Thanks


回答1:


SWIG comes with pre-written interface files for many C++ constructs. The are found in SWIG's Lib directory for many languages, including Java.

Add %include <std_string.i> in your SWIG interface file. Check SWIG's Lib/Java directory for support for other constructs as well.




回答2:


std::string has a member function c_str that does essentially that. It would probably make sense to write a wrapper function that calls your function and returns the corresponding c string.



来源:https://stackoverflow.com/questions/4937979/swig-convert-return-type-stdstring-to-java-byte

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!