skip to Main Content

I have tried to change the encoding in vs code, but the Russian characters keep showing as "???" in the terminal.

3

Answers


  1. Chosen as BEST ANSWER

    The solution was to tick "Use Unicode UTF-8 for worldwide language support" in the System Region Settings.


  2. Try add setlocale(LC_ALL, "Russian") to begin of your code.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search