Solve the problem of Chinese garbled characters in VS Code terminal

When I use VSCode to compile and run under Windows, the problem of Chinese garbled characters appears. Today I encountered this situation. I searched online for a long time and still did not find the correct solution. Now I will share my method.

The cmd under Chinese windows uses GBK encoding by default. Every time you need it, just enter the command: chcp 65001 in the VSCode terminal. Switching the code page to use UTF-8 can solve the problem of Chinese code, but this method is too troublesome. I have to enter a command every time I enter the terminal. Is there a permanent solution? Of course there is.

Permanently modify the console code page of VSCode to 65001:

In VSCode, open "File" - "Preferences" - "Settings", then set it in setting.json, and copy the following three lines into it:

{ “editor.fontSize”: 18, “terminal.integrated.shellArgs.windows”: [“/K chcp 65001 >nul”], “terminal.integrated.fontFamily”: “Lucida Console”, } /K chcp 65001 >nul The meaning is to set the encoding to 65001 when running cmd; >nul is to avoid outputting the encoding modification information on the console, otherwise active code page: 65001 will be output; at the same time, two easter eggs are given, for example: editor.fontSize: 20 (Change the font size to 20); terminal.integrated.fontFamily: “Courier New” (Change the font size to “Courier New”). You can fill this in according to your own needs. Of course, you don’t need to write it if you don’t need it.









Guess you like

Origin blog.csdn.net/weixin_43717839/article/details/133276551