Skip to content

Instantly share code, notes, and snippets.

@JPGygax68
Last active July 15, 2022 08:13
Show Gist options
  • Save JPGygax68/07e971201770f3df5a35 to your computer and use it in GitHub Desktop.
Save JPGygax68/07e971201770f3df5a35 to your computer and use it in GitHub Desktop.
#Unicode conversion: UTF-8 to UTF-32 in C++11
#include <codecvt>
using namespace std;
#if _MSC_VER >= 1900
wstring_convert<codecvt_utf8<int32_t>, int32_t> utf32conv;
auto utf32 = utf32conv.from_bytes("The quick brown fox jumped over the lazy dog.");
// use reinterpret_cast<const char32_t *>(utf32.c_str())
#else
wstring_convert<codecvt_utf8<char32_t>, char32_t> utf32conv;
auto utf32 = utf32conv.from_bytes("The quick brown fox jumped over the lazy dog.");
// use utf32.c_str()
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment