Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would strongly recommend using UTF-8 internally in your application, using regular old <code>char*</code> or <code>std::string</code> for data storage. For interfacing with APIs that use a different encoding (ASCII, UTF-16, etc.), I'd recommend using <a href="http://www.gnu.org/software/libiconv/" rel="noreferrer">libiconv</a>, which is licensed under the LGPL.</p> <p>Example usage:</p> <pre><code>class TempWstring { public: TempWstring(const char *str) { assert(sUTF8toUTF16 != (iconv_t)-1); size_t inBytesLeft = strlen(str); size_t outBytesLeft = 2 * (inBytesLeft + 1); // worst case mStr = new char[outBytesLeft]; char *outBuf = mStr; int result = iconv(sUTF8toUTF16, &amp;str, &amp;inBytesLeft, &amp;outBuf, &amp;outBytesLeft); assert(result == 0 &amp;&amp; inBytesLeft == 0); } ~TempWstring() { delete [] mStr; } const wchar_t *Str() const { return (wchar_t *)mStr; } static void Init() { sUTF8toUTF16 = iconv_open("UTF-16LE", "UTF-8"); assert(sUTF8toUTF16 != (iconv_t)-1); } static void Shutdown() { int err = iconv_close(sUTF8toUTF16); assert(err == 0); } private: char *mStr; static iconv_t sUTF8toUTF16; }; iconv_t TempWstring::sUTF8toUTF16 = (iconv_t)-1; // At program startup: TempWstring::Init(); // At program termination: TempWstring::Shutdown(); // Now, to convert a UTF-8 string to a UTF-16 string, just do this: TempWstring x("Entr\xc3\xa9""e"); // "Entrée" const wchar_t *ws = x.Str(); // valid until x goes out of scope // A less contrived example: HWND hwnd = CreateWindowW(L"class name", TempWstring("UTF-8 window title").Str(), dwStyle, x, y, width, height, parent, menu, hInstance, lpParam); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload