Conversion from basic_string to jstring
10,943
You'll need to convert the std::basic_string into UTF-8. Look into what your wstring -> string conversion does.
Sun has a JNI tutorial that shows how to convert a char* into a jstring (using some UTF conversion routines). You could use your wstring->string, then pass in string.c_str() to the NewStringUTF function:
Untested Code:
JNIEXPORT jstring JNICALL StringTest(JNIEnv *env) {
const char* test = "something";
return env->NewStringUTF(test);
}
Author by
sparkFinder
Updated on July 19, 2022Comments
-
sparkFinder almost 2 years
I'm using a
basic_string<wchar_t>
type and need to convert it into a jstring to pass through a JNI layer. I'm wondering what the best way to do that is. I have a function that can give me astd::string
from mybasic_string<wchar_t>
type, so an answer to that would also be cool.Cheers.