I have tried to change the encoding in vs code, but the Russian characters keep showing as "???" in the terminal.
3
The solution was to tick "Use Unicode UTF-8 for worldwide language support" in the System Region Settings.
Try add setlocale(LC_ALL, "Russian") to begin of your code.
setlocale(LC_ALL, "Russian")
auto utf16_to_utf8 = [](const std::wstring &value) -> std::string { int len = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, NULL, 0, 0, 0); if (len) { std::string utf8 = std::string(len, ' '); WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, &utf8[0], len, 0, 0); return utf8; } return std::string(); }; auto utf8_to_utf16 = [](const std::string &value) -> std::wstring { int len = MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, NULL, 0, 0, 0); if (len) { std::wstring utf16 = std::wstring(len, ' '); MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, &utf16[0], len, 0, 0); return utf16; } return std::string(); };
Then do: std::wcout<<utf8_to_utf16(u8"Приветn"); Windows terminals have been notoriously bad with displaying UTF-8, until recently in Windows 10 or 11. So you’d be better off outputting UTF-16.
std::wcout<<utf8_to_utf16(u8"Приветn");
Click here to cancel reply.
3
Answers
The solution was to tick "Use Unicode UTF-8 for worldwide language support" in the System Region Settings.
Try add
setlocale(LC_ALL, "Russian")
to begin of your code.Then do:
std::wcout<<utf8_to_utf16(u8"Приветn");
Windows terminals have been notoriously bad with displaying UTF-8, until recently in Windows 10 or 11. So you’d be better off outputting UTF-16.