Created
November 6, 2014 19:33
-
-
Save gchudnov/c1ba72d45e394180e22f to your computer and use it in GitHub Desktop.
C++ string conversion UTF8 <-> UTF16
This file contains 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 <string> | |
#include <locale> | |
#include <codecvt> | |
//UTF-8 to UTF-16 | |
std::string source; | |
//... | |
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert; | |
std::u16string dest = convert.from_bytes(source); | |
//UTF-16 to UTF-8 | |
std::u16string source; | |
//... | |
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert; | |
std::string dest = convert.to_bytes(source); |
codecvt_utf8* with wstring_convert deprecated in C++17, removed in C++26
wstring(wchar_t) is utf-32 on linux.
It's in the standard library of cpp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you a lot,
im tryna convert wstring(utf16) <=> string(utf8), so i did a small fixes on your code.
here is it