问题
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