问题
I have some code from a Chinese business partner, and all of the comments in the code are in Chinese. However, Visual Studio displays them as gibberish. How can I get them to display properly. Here is a code example with some comments converted to gibberish:
//Á¬½Óµ½·þÎñÆ÷
void CTestAPIDlg::OnBnClickedButton2()
{
UpdateData(TRUE);
//ÉèÖÃÊÇ·ñ¼Ç¼ÈÕÖ¾
m_ObjRSI->EnableLog(m_bIsOnLogReg,m_bIsOnLogComm);
//ÅжÏÊÇ·ñÆôÓôúÀí
if (m_bIsOnProxy)
{
//´úÀí²ÎÊý
char proxyIP[64];
ZeroMemory(proxyUserPwd,sizeof(proxyUserPwd));
//×¢£º´Ë´¦ÒòΪÊÇʹÓÃunicode±àÒ룬ËùÒÔÒª×Ö·ûת»»£¬ÏÂͬ.
WideCharToMultiByte(CP_ACP,0,m_strProxyIP,-1,proxyIP,64,NULL,NULL);
etc...
Thanks in advance for any help...
回答1:
Ask your partner to save the source code file encoded in UTF-16 or UTF-8. It is still not the default encoding for C++ source code, Unicode is slow to catch up. File + Save As, click on the arrow of the Save button, Save with Encoding, choose UTF-8.
You should be able to do this yourself as well. File + Open, select the .cpp file(s), click on the arrow of the Open button, Open With, select "C++ Source Code Editor (with encoding)". Pick the correct Chinese encoding (there are several to choose from) from the Encoding dialog box.
回答2:
You can use applocale, download it from here: http://www.microsoft.com/en-us/download/details.aspx?id=13209.
This is an old app but works well on Win7 and Win8 (tested). When installing, simply make sure to run it as admin. Then later on, run devnev.exe (visual studio) using applocale and set the locale to Chinese. I just tested this works perfectly well.
来源:https://stackoverflow.com/questions/2776661/how-can-i-get-visual-studio-2010-to-show-chinese-comments-properly