Convert from basic_string to jstring

I am using the type basic_string<wchar_t> and must convert it to jstring to pass through the JNI layer. I am wondering how best to do this. I have a function that can give me std::string from my type basic_string<wchar_t> , so the answer to that would also be cool.

Greetings.

+8
source share
1 answer

You will need to convert std :: basic_string to UTF-8. See what your wstring -> string conversion does.

Sun has a JNI tutorial that shows how to convert char * to jstring (using some UTF conversion procedures). You can use the string wstring-> and then pass string.c_str () to the NewStringUTF function:

Unverified code:

 JNIEXPORT jstring JNICALL StringTest(JNIEnv *env) { const char* test = "something"; return env->NewStringUTF(test); } 
+5
source

All Articles