In program development, our unified encoding is UTF-8, which is very important, but we still encounter many garbled problems. There are many reasons for garbled codes, so I won’t be here for the time being. Summarize more. Here only explain that using the console to execute some self-written programs under the window, or when interactive programming will often encounter garbled problems, this is because the default encoding of Window cmd is GBK. Chinese and special characters garbled caused by inconsistency with the UTF-8 used by the program.
p>
The first way: temporarily modify the display code of the console
use The chcp command, such as chcp 65001, will change the current code page to utf-8 encoding this time, but this method will automatically fail after closing cmd.
Commonly used codes and corresponding code values (decimal):
第Two ways: permanent modification
Permanent modification is achieved by modifying the registration form.
Open the registry method: win+r -> regedit
Locate to: HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe
p>
It should be noted that there is no such key value by default. Only right-click on the title bar to modify the settings will appear. Delete this item, the default settings of the console will be used. If you want to modify, you can right-click on the cmd title bar to set it, modify an attribute at will, and then refresh the registry.
p>
If there is no CodePage on the right, right-click to create a new DWORD value and directly modify it to 65001 (65001 in decimal). The same can also be modified: powershell The default encoding. If you can’t modify it because of permissions, you can right-click the red box on the left, select permissions, and give yourself full control permissions!
More dry goods notes, follow WeChat public account: Laojiu School