I published on GitHub a header-only library (Utf8Conv) that implements some convenient functions to convert text between UTF-8 and UTF-16 Unicode encodings.
I developed the library using Visual Studio 2019 with C++17 features enabled.
The library is very easy to use. Once you have included the library header Utf8Conv.hpp, you can simply invoke its functions like this:
#include "Utf8Conv.hpp" // Library header // Note: Library functions live under the Utf8Conv namespace. ... // Convert from UTF-8 to UTF-16 wstring utf16String = Utf8ToUtf16(utf8String); // Convert from UTF-16 to UTF-8 string utf8String = Utf16ToUtf8(utf16String);
The input strings can be expressed via std::[w]string objects, and also using std::[w]string_views as well.
The returned strings are always instances of std::string for UTF-8-encoded text and std::wstring for UTF-16 text.