VS of Chinese garbage problem

 

Chinese garbled reasons :

1. Chinese at different coding formats , stored in a different way .

2. If the program is A coding compiled to run , but it is the console B coding to show , there will be garbled .

3. VS console default encoding is GB2312, numbering number is 836

Note : GBK coding is compatible GB2312 is , a general description of GBK often refers BG2312

  If the encoding of the source code files if other encoding format , it will lead to Chinese garbled .

 

Normal scenario :

In vs When creating a new file , the file is by default GB2312 encoding .

Because the default console is GB2312 coding , so under normal circumstances , it would not appear Chinese garbled .

 

Error scenario :

1. directly into the other already created source code files in the project ,

If the file is not BG2312 coding , and contains Chinese words , it must be Chinese garbled .

2. Copy the files from the other code to vs file , it may lead to confusion coding .

3. Network programming , and interactive communications server , coded across likely to be different .

  Our " hacking system " server-side Trojan horse , is UTF-8 encoding format .

 

Solution one encoding the modified file

Modify the source code files " encoding format ", making the console and encoding format consistent .

Console default encoding format is 936

 

Encoding format code files , by vs easily modified :

First with vs open the corresponding file , then the following operations :

 

 

If the same coding and procedures of the console, there are Chinese garbage, we need to modify the properties of the console,

Right-click the console title bar and select "Properties", check the "legacy console"

And then re-run.

 

Solution two enforce the implementation of the specified file

 

It does not modify the encoding of the file , but directly specify the encoding used when the program is executed , the same console code and make it run the program .

#pragma execution_character_set("gbk")

 

Third solution modify the encoding format console

Modify vs coding console , making coding and source code consistent .

Modify the registry , you can modify the console encoding format .

 

Note :

We do not recommend using this mode .

因为, 把控制台的默认编码改为其他编码后, 在该控制台输入中文, 很可能导致输入的中文无法识别.

vs2010中存在该问题.

 

解决方案四对数据进行编码转换

适用于: 服务器端和客户端, 或多个客户端之间的编码不一致时.

1) 收到对方的其他编码数据时, 先使用特定的接口来进行编码转换.

发送本地数据给对方之前, 先使用特定的接口来进行编码转换.

Guess you like

Origin www.cnblogs.com/yangrui1/p/11783764.html