How to solve "Chinese Garbled(中文乱码)" in UTF-8?

Answered

System:Win11 Chinese version

Clion:2023.1

 

Hello,can you help me how to solve "Chinese Garbled(中文乱码)"?

When I run directly, Chinese in console is garbled

But when I run in debug:

it shows correct:

 

By the way, i try to change the cpp encoding to GBK, it shows correct by run directly

but run in debug is garbled:

 

Here are my config:

Settings->File Encodings:

Global Encoding, Project Encoding , properties files: UTF-8

Settings->Toolchains:

default is VS

Settings->Cmake:

 

vmoptions:

-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8
 
 
how to sovle it by UTF-8 and shows correct?
I am looking forward to your help, thank you very much.
 
2
7 comments

Hello!

Please go to File | Settings | Advanced Setting- Run/Debug and uncheck the Emulate terminal in the output console option, it should help.

0

I  uncheck the Emulate terminal in the output console option, it can't help

 

std::cout << "Hello12, 控制台输出中文有乱码11!" << std::endl;
 
it shows:
Hello12, 鎺у埗鍙拌緭鍑轰腑鏂囨湁涔辩爜11!

 

0

It seems you faced https://youtrack.jetbrains.com/issue/CPP-28938. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

For now, as a workaround, you can use the "Run in external console" option in your run/debug configuration (Run | Edit Configurations...).

Or you can try disabling run.processes.with.pty as suggested in this comment.

0

I encountered the same problem in clion2023.1 under windows10, what is the reason?

0

1191432275 there is a bug in CLion, please take a look at my comment above.

0

This issue may due to the default encoding for different language in Windows. (For example, GBK is used for simplified Chinese version.) I check the "Use Unicode UTF-8 for worldwide language support" in Windows language settings and then the text is displayed correctly. (See: https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8#answer-1435645)

0

我目前发现的解决方案:

1.  “使用 Unicode UTF-8 提供全球语言支持”是在 Windows 系统设置中的一项配置。具体步骤如下:

       1).打开“设置区域格式”。

       2).选择“管理语言设置”。

       3).选择“更改系统区域设置”。

       4).在“切换系统区域设置”部分,勾选“Beta版:使用 Unicode UTF-8 提供全球语言支持”。

win10我不知道有没有“使用 Unicode UTF-8 提供全球语言支持”这个按钮。而且这个方法有弊端, 在chrome控制台输入英文引号看起来像中文引号, 很不舒服

2. 针对控制台和注册表双管齐下

        1). 向 `Microsoft.PowerShell_profile.ps1` 文件 写入 `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8`

        2). 修改注册表, 就像 Clark1729 提到的 stackoverflow 中的解决方案  `win+R` 输入 `regedit` 来到注册表管理。 进入到 `HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor` 中, 检查是否有 `Autorun`, 如果有把它的值改成 `@chcp 65001>nul` 如果没有, 新建一个字符串类型的值, 如下:

0

Please sign in to leave a comment.