Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's no way to write the string literal directly in UTF-8 with the current versions of VC++. A future version should have <a href="http://en.wikipedia.org/wiki/C++11#New_string_literals" rel="nofollow">UTF-8 string literals</a>.</p> <p>I tried pasting non-ASCII text directly into a string literal in a source file and saved the file as UTF-8. Looking at the source file in a hex editor confirmed that it's saved as UTF-8, but that still doesn't do what you want. At compile time, those bytes are either mapped to a character in the current code page or you get a warning.</p> <p>So the most portable way to create a string literal right now is to explicitly write the octets as you've been doing.</p> <p>If you want to do a run-time conversion, there are a couple options.</p> <ol> <li>The Windows API has <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd374130%28v=vs.85%29.aspx" rel="nofollow">WideCharToMultiByte</a>, which can take a text as UTF-16 and convert it to multibyte encodings like UTF-8.</li> <li>If you're using a new enough version of the compiler and the C++ runtime, you can use <a href="http://en.cppreference.com/w/cpp/locale/codecvt" rel="nofollow"><code>std::codecvt</code></a> to transform your wide character string into UTF-8.</li> </ol> <p>You could use one of these techniques to write a little utility that does the conversion and outputs them as the explicit octets you would need for a string literal. You could then copy and paste the output into your source code.</p>
 

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