Skip to content

Instantly share code, notes, and snippets.

@rednaxelafx
Created September 18, 2013 07:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rednaxelafx/6605567 to your computer and use it in GitHub Desktop.
Save rednaxelafx/6605567 to your computer and use it in GitHub Desktop.
Demo of using C++11's u16string with Unicode string literal syntax
#include <codecvt> // for codecvt_utf8
#include <iostream> // cor cout
#include <locale> // for wstring_convert
#include <string> // for string, u16string
using namespace std;
// Compiles on LLVM 3.3 with:
// clang++ -std=c++11 -stdlib=libc++ xxx.cpp
int main() {
u16string s = u"alpha";
wstring_convert<codecvt_utf8<char16_t>, char16_t> cv;
cout << cv.to_bytes(s) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment