Last active
July 15, 2022 08:13
-
-
Save JPGygax68/07e971201770f3df5a35 to your computer and use it in GitHub Desktop.
#Unicode conversion: UTF-8 to UTF-32 in C++11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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