title: Convert JNI UTF-16 string to standard C++ UTF-8 string
body: <p>I need to convert a UTF-16 string to a UTF-8 string.</p>
  
  <pre><code>const unsigned short *utf16string = ...;
  const char *utf8string = convertUTF16toUTF8(utf16string);
  </code></pre>
  
  <p>Can anybody help me find/write the function <code>const char* convertUTF16toUTF8(const unsigned short* utf16string)</code>?</p>
  
  <p>The types can't be changed, unfortunately, and I don't have access to C++11. I've been beating my head at this for hours and can't find any solutions.</p>
  
  <p>Please help me. I believe in you, StackOverflow!</p>
  
  <p>P.S. If anybody needs to know, I'm making a game using cocos2d-x and I'm trying to get a string using the JNI callbacks. JNI has a UTF version of the <code>GetString...</code> functions, yet these are buggy according to my own experience and <a href="http://en.wikipedia.org/wiki/Java_Native_Interface" rel="nofollow">Wikipedia</a>, so I need to convert the strings using the raw functions.</p>