简体   繁体   English

VS2010中的字符集

[英]Character Sets in VS2010

I am using VS2010 and I have these in my code: 我正在使用VS2010,并且代码中包含以下内容:

::MessageBox(0, "Init FAILED", 0, 0);

When I compiled the project, I got the error that cannot convert parameter 2 from 'const char [25]' to 'LPCWSTR'. 编译项目时,出现错误,无法将参数2从'const char [25]'转换为'LPCWSTR'。 I searched the problem on the Internet, people told me to change the 'character sets' option in my project settings from 'Unicode' to 'Not Set'. 我在Internet上搜索了问题,人们告诉我将项目设置中的“字符集”选项从“ Unicode”更改为“未设置”。 But it does not work. 但这行不通。 When I run these codes: 当我运行这些代码时:

#ifdef UNICODE
    printf("unicode");
#else
    printf("others");
#endif

I get the same answer "unicode" no matter what option I have chosen. 无论选择哪种选项,我都会得到相同的答案“ unicode”。 What should I do to handle the problem? 我应该怎么做才能解决这个问题?

To answer your original question, you didn't need to change the character set. 要回答您的原始问题,您无需更改字符集。 The solution is to use the _T() macro that is defined in tchar.h. 解决方案是使用tchar.h中定义的_T()宏。

::MessageBox(0, _T("Init Failed"), 0, 0);

The _T() macro will either specify a wide string by appending an "L" onto the string, or an ANSI string by leaving the string alone. _T()宏将通过在字符串上附加“ L”来指定宽字符串,或者通过不使用字符串来指定ANSI字符串。

You should change the character set only if you truly want to use the character set you're changing to. 当您确实要使用要更改的字符集时, 应更改字符集。 You don't change the character set just because your code doesn't compile. 您不会仅因为代码未编译就更改字符集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM