Solution to the problem of Chinese garbled characters displayed on the command line of VsCode

In the beginning, I checked a lot of articles to solve this problem. There are methods:

0. First execute chcp 65001 on the command line (change to utf-8 encoding) and then run the program (but not once and for all); 1. Modify the settings.json of VsCode; 2. Also modify the system registry; 3. Still It is possible to modify the global character encoding of the system to utf-8.

After reading a blogger's method later, I found that there is a very simple way.

Solution 1 (simple and elegant way): Add a system() at the beginning of the program and execute chcp 65001 (change to utf-8 encoding). Every time the program is executed, Chinese can be printed correctly on the command line.

system("chcp 65001"); /* cmd chcp 命令切换字符编码为 utf-8 以显示中文 */

Solution 2: Click "UTF-8" in the lower right corner, select "Reopen by encoding", enter "GB 2312", and select "Simplified Chinese (GB 2312)". 

Select "Reopen with encoding"

 

Guess you like

Origin blog.csdn.net/weixin_53514496/article/details/125352850